2 changed files with 45 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||
public class Employee { |
|||
// 私有实例变量
|
|||
private String id; |
|||
private String name; |
|||
private String department; |
|||
private double salary; |
|||
|
|||
// 静态变量(所有员工共享)
|
|||
private static String companyName; |
|||
|
|||
// 最低工资常量
|
|||
public static final double MIN_SALARY = 2000.0; |
|||
|
|||
// 构造方法
|
|||
public Employee(String id, String name, String department, double salary) { |
|||
this.id = id; |
|||
this.name = name; |
|||
this.department = department; |
|||
|
|||
// 工资校验
|
|||
if (salary >= MIN_SALARY) { |
|||
this.salary = salary; |
|||
} else { |
|||
this.salary = MIN_SALARY; |
|||
} |
|||
|
|||
// 给公司名称赋值
|
|||
companyName = "我的公司"; |
|||
} |
|||
|
|||
// 显示员工信息
|
|||
public void showInfo() { |
|||
System.out.println("工号:" + id); |
|||
System.out.println("姓名:" + name); |
|||
System.out.println("部门:" + department); |
|||
System.out.println("工资:" + salary); |
|||
System.out.println("公司:" + companyName); |
|||
} |
|||
|
|||
// 程序入口
|
|||
public static void main(String[] args) { |
|||
Employee emp = new Employee("001", "张三", "技术部", 5000); |
|||
emp.showInfo(); |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 136 KiB |
Loading…
Reference in new issue