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.
85 lines
2.1 KiB
85 lines
2.1 KiB
package w3;
|
|
|
|
public class Employee {
|
|
private static String companyName;
|
|
private String id;
|
|
private String name;
|
|
private String department;
|
|
private double salary;
|
|
private static final double MIN_SALARY = 2000;
|
|
|
|
static {
|
|
// 这里改成通用公司名,无任何个人信息
|
|
companyName = "科技有限公司";
|
|
}
|
|
|
|
public Employee(String id, String name, String department, double salary) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.department = department;
|
|
setSalary(salary);
|
|
}
|
|
|
|
public static String getCompanyName() {
|
|
return companyName;
|
|
}
|
|
|
|
public static void setCompanyName(String companyName) {
|
|
Employee.companyName = companyName;
|
|
}
|
|
|
|
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 {
|
|
System.out.println("工资不能低于最低工资标准 " + MIN_SALARY);
|
|
this.salary = MIN_SALARY;
|
|
}
|
|
}
|
|
|
|
public void raiseSalary(double percent) {
|
|
double newSalary = this.salary * (1 + percent / 100);
|
|
if (newSalary >= MIN_SALARY) {
|
|
this.salary = newSalary;
|
|
} else {
|
|
this.salary = MIN_SALARY;
|
|
}
|
|
}
|
|
|
|
public void printInfo() {
|
|
System.out.println("公司:" + companyName);
|
|
System.out.println("工号:" + id);
|
|
System.out.println("姓名:" + name);
|
|
System.out.println("部门:" + department);
|
|
System.out.println("工资:" + String.format("%.2f", salary));
|
|
System.out.println("------------------------");
|
|
}
|
|
}
|