You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.1 KiB
80 lines
2.1 KiB
package w3;
|
|
|
|
public class Employee {
|
|
// 静态变量:公司名称
|
|
public static String companyName;
|
|
|
|
// 成员变量
|
|
private String id; // 工号
|
|
private String name; // 姓名
|
|
private String department;// 部门
|
|
private double salary; // 工资
|
|
|
|
// 最低工资标准
|
|
private static final double MIN_SALARY = 2000;
|
|
|
|
// 构造方法:创建对象时赋值
|
|
public Employee(String id, String name, String department, double salary) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.department = department;
|
|
setSalary(salary); // 调用方法保证工资合法
|
|
}
|
|
|
|
// get/set 方法
|
|
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 getDepartment() {
|
|
return department;
|
|
}
|
|
|
|
public void setDepartment(String department) {
|
|
this.department = department;
|
|
}
|
|
|
|
public double getSalary() {
|
|
return salary;
|
|
}
|
|
|
|
public void setSalary(double salary) {
|
|
if (salary >= MIN_SALARY) {
|
|
this.salary = salary;
|
|
} else {
|
|
this.salary = MIN_SALARY;
|
|
System.out.println("工资过低,自动调整为:" + MIN_SALARY);
|
|
}
|
|
}
|
|
|
|
// 涨薪方法
|
|
public void raiseSalary(double percent) {
|
|
double newSalary = salary * (1 + percent / 100);
|
|
setSalary(newSalary);
|
|
}
|
|
|
|
// 打印信息
|
|
@Override
|
|
public String toString() {
|
|
return "员工{" +
|
|
"公司='" + companyName + '\'' +
|
|
", 工号='" + id + '\'' +
|
|
", 姓名='" + name + '\'' +
|
|
", 部门='" + department + '\'' +
|
|
", 工资=" + salary +
|
|
'}';
|
|
}
|
|
}
|
|
|
|
|