JAVA创建职工类代码 java代码组成
用Java语言定义一个员工类Employee
public class Employee {
创新互联网站建设公司,提供成都网站建设、网站建设,网页设计,建网站,PHP网站建设等专业做网站服务;可快速的进行网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,是专业的做网站团队,希望更多企业前来合作!
private String id; // 员工ID号
private String name; // 姓名
private int age; // 年龄
private boolean sex; // 性别(其中:true表示男,false表示女)
private String phone; // 联系电话
private float salary; // 薪水
Employee(String sId, String sName, int sAge, boolean sSex, String sPhone,
float sSalary) {
this.id = sId;
this.name = sName;
this.age = sAge;
this.sex = sSex;
this.phone = sPhone;
this.salary = sSalary;
}
public String toString() {
return "员工ID号:" + this.id + "\n员工姓名:" + this.name + "\n员工年龄:"
+ this.age + "\n员工性别:" + (this.sex == true ? "男" : "女")
+ "\n联系电话:" + this.phone + "\n薪水:" + this.salary;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
}
麻烦各位java程序大神,帮助我一下,给我下面一道java题的代码呗?我是真不会。
/**
* 职工类
*/
public class Employee {
private String identifier;//职工编号
private String name;//职工姓名
public Employee() {
}
public Employee(String identifier, String name) {
this.identifier = identifier;
this.name = name;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void work() {
System.out.println("工作时间:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName());
}
}
/**
* 经理类
*/
public class Manager extends Employee{
private String department;//工作部门
public Manager(String identifier, String name) {
super(identifier, name);
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName()+",负责的工作部门:"+getDepartment());
}
}
/**
* 董事长类
*/
public class Chairman extends Employee{
@Override
public void work() {
System.out.println("董事长主持召开股东大会");
}
}
/**
* 测试类:类名DemoTest03
*/
public class DemoTest03 {
public static void main(String[] args) {
Employee e = new Employee("07","益达");
Manager m = new Manager("01","小黑");
m.setDepartment("爱情公寓");
Chairman c = new Chairman();
e.showInfo();
e.work();
m.showInfo();
c.work();
}
}
用Java编写一个员工类程序:1.属性:员工编号,员工姓名,基本工资,奖金,2.构造方法:至少两个
用Java编写一个员工类程序:1.属性:员工编号,员工姓名,基本工资,奖金,2.构造方法:至少两个。如下:
package com.test;
public class Employee {
/**
* 员工编号
*/
private String number;
/**
* 员工姓名
*/
private String name;
/**
* 员工薪水
*/
private double salary;
/**
* 无参数构造函数
*/
public Employee() {
}
/**
* 给属性赋值构造函数
* @param number
* @param name
* @param salary
*/
public Employee(String number, String name, double salary) {
super();
this.number = number;
this.name = name;
this.salary = salary;
}
public static void main(String[] args) {
//员工一,并且构造函数里设置值
Employee e1 = new Employee("e0001", "xiaoming", 5000.0);
System.out.println("员工一:" + e1);
//员工二,用set设置值,get的话可以获取到员工某个属性
Employee e2 = new Employee();
e2.setName("小二");
e2.setNumber("e0002");
e2.setSalary(5500.1);
System.out.println("员工二:" + e2);
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Employee [number=" + number + ", name=" + name + ", salary=" +
salary + "]";
}
}
运行结果:
员工一:Employee [number=e0001, name=xiaoming, salary=5000.0]
员工二:Employee [number=e0002, name=小二, salary=5500.1]
用java编写员工类Employee
public class Employee {
private int id;
private byte sex;
private String name;
private String duty;
private float salary;
private int holidays;
public Employee(int id,byte sex,String name,String duty, float salary,int holidays){
this.id = id;
this.sex = sex;
this.name = name;
this.duty = duty;
this.salary = salary;
this.holidays = holidays;
}
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public int getHolidays() {
return holidays;
}
public void setHolidays(int holidays) {
this.holidays = holidays;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public byte getSex() {
return sex;
}
public void setSex(byte sex) {
this.sex = sex;
}
/**
* display(),无返回值,该方法能打印员工的姓名、性别以及职务
* @param employee
*/
public void display(Employee employee){
System.out.println("员工姓名为: " + employee.getName());
if(employee.getSex()==1){
System.out.println("员工性别为: 男 ");
}else if(employee.getSex()==2){
System.out.println("员工性别为:女 ");
}
System.out.println("员工职务为: " + employee.getDuty());
}
/**
* getDecMoney(int day) 返回值是int型。
* 如果请假天数=3,则扣款为30×请假天数;
* 如果请假天数超过3天,则扣款为50×请假天数。
* @param day
* @return
*/
public int getDecMoney(int day){
int deduction = 0; //扣除的工资
if(day = 3){
deduction = 30*day;
}else if(day 3){
deduction = 50*day;
}
return deduction;
}
public static void main(String[] args){
//创建一个员工类的对象
Employee employee = new Employee(123456789,(byte) 1,"陈冠希","生产帽子的(绿色)",(float) 500.8,5);
employee.display(employee); //调用display()
int deduction = employee.getDecMoney(employee.getHolidays());//调用getDecMoney()
System.out.println("该员工因请假扣除工资" + deduction + "元");
}
}
当前题目:JAVA创建职工类代码 java代码组成
网站URL:http://scyanting.com/article/doopids.html