Browse Source

上传文件至 'W3'

main
Zhuhuairui 3 weeks ago
parent
commit
2e09478f3e
  1. 45
      W3/Employee.java
  2. BIN
      W3/屏幕截图 2026-03-26 114736.png

45
W3/Employee.java

@ -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();
}
}

BIN
W3/屏幕截图 2026-03-26 114736.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Loading…
Cancel
Save