员工类型代码Java 员工类型编码

java如何设计一个员工类employee?

public class Employee{    private String name;//姓名    private int salary;//薪水

创新互联是一家集网站建设,禄丰企业网站建设,禄丰品牌网站建设,网站定制,禄丰网站建设报价,网络营销,网络优化,禄丰网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

public Employee()

{

//无参构造函数    }

public Employee(String name,int  salary)

{        //有参构造函数        this.name=name;

this.salary=salary;        //局部变量若与类变量同名,则以局部变量为准,类变量需要用this引用    }

public void setName(String name){

this.name=name;    }

public String getName()

{        return this.name;

}

public void setSalary(int salary)

{        this.salary=salary;    }

public int getSalary()

{        return this.salary;    }}

//测试类

public class Test()

{    public static void main(String args[])

{        Employee e = new Employee("张三",1200);

System.out.println(e.getName());//输出姓名

System.out.println(e.getSalary());//输出薪水

Employee e2= new Employee();

e2.setName("李四");

e.setSalary(1000);

System.out.println(e2.getName());//输出姓名

System.out.println(e2.getSalary());//输出薪水    }

}

*运行结果

张三

1200

李四

1000

*

用Java语言定义一个员工类Employee

public class Employee {

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编写员工类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 员工类型编码
转载源于:http://myzitong.com/article/doijpph.html