1 changed files with 84 additions and 0 deletions
@ -0,0 +1,84 @@ |
|||
public class Employee{ |
|||
private String id; |
|||
private String name; |
|||
private String department; |
|||
private double salary; |
|||
private static String companyName; |
|||
|
|||
public Employee(){ |
|||
} |
|||
public Employee(String id,String name,String department,double salary){ |
|||
this.id=id; |
|||
this.name=name; |
|||
this.department=department; |
|||
this.setSalary(salary); |
|||
} |
|||
|
|||
public static String getCompanyName(){ |
|||
return companyName; |
|||
} |
|||
|
|||
public static void setCompanyName(String companyName){ |
|||
Employee.companyName=companyName; |
|||
} |
|||
|
|||
public String getdepartment(){ |
|||
return this.department; |
|||
} |
|||
public double getSalary(){ |
|||
return this.salary; |
|||
} |
|||
public String getname(){ |
|||
return this.name; |
|||
} |
|||
public String getid(){ |
|||
return this.id; |
|||
} |
|||
|
|||
public void setId(String id){ |
|||
this.id=id; |
|||
} |
|||
public void setDepartment(String department){ |
|||
this.department=department; |
|||
} |
|||
public void setName(String name){ |
|||
this.name=name; |
|||
} |
|||
public void setSalary(double setsalary){ |
|||
if(setsalary>=2000.0){ |
|||
this.salary=setsalary; |
|||
} else{ |
|||
System.out.println("工资设置失败,自动设为2000元"); |
|||
this.salary=2000.0; |
|||
} |
|||
} |
|||
public void raiseSalary(double percent){ |
|||
if(percent>0.0){ |
|||
this.salary*=(1+percent/100.0); |
|||
} else { |
|||
System.out.println("输入有误"); |
|||
} |
|||
} |
|||
public void printInfo() { |
|||
System.out.println("公司名称: " + Employee.companyName); |
|||
System.out.println("员工ID: " + this.id); |
|||
System.out.println("姓名: " + this.name); |
|||
System.out.println("部门: " + this.department); |
|||
System.out.println("工资: " + this.salary); |
|||
System.out.println("--------------------"); |
|||
} |
|||
public static void main(String[] args){ |
|||
Employee employee1 = new Employee("E521","Mary","manager",30000); |
|||
Employee employee2 = new Employee("002", "李四", "市场部", 6000); |
|||
Employee.setCompanyName("思源股份有限公司"); |
|||
System.out.println("员工"+employee1.getname()+"的工资是"+employee1.getSalary()); |
|||
//员工Mary的工资是30000.0
|
|||
employee1.raiseSalary(10); |
|||
//调薪后员工Mary的工资是33000.0
|
|||
System.out.println("调薪后员工"+employee1.getname()+"的工资是"+employee1.getSalary()); |
|||
employee1.printInfo(); |
|||
employee2.printInfo(); |
|||
//工资设置失败
|
|||
employee1.setSalary(1000); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue