diff --git a/W3/Employee.java b/W3/Employee.java new file mode 100644 index 0000000..3a0c4c1 --- /dev/null +++ b/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(); + } +} \ No newline at end of file diff --git a/W3/屏幕截图 2026-03-26 114736.png b/W3/屏幕截图 2026-03-26 114736.png new file mode 100644 index 0000000..6ae0918 Binary files /dev/null and b/W3/屏幕截图 2026-03-26 114736.png differ