From efb0d7ab899850eb19420372cba2ea33a4ca5336 Mon Sep 17 00:00:00 2001 From: zhangsiyuan <3837703520@qq.com> Date: Tue, 24 Mar 2026 12:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=A0=E6=80=9D=E6=B8=8A-202401070104-w3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w3/Employee.java | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 w3/Employee.java diff --git a/w3/Employee.java b/w3/Employee.java new file mode 100644 index 0000000..59608f8 --- /dev/null +++ b/w3/Employee.java @@ -0,0 +1,84 @@ +public class Employee{ + private String id; + private String name; + private String department; + private double salary; + private static String companyName; + + public Employee(){ + } + public Employee(String id,String name,String department,double salary){ + this.id=id; + this.name=name; + this.department=department; + this.setSalary(salary); + } + + public static String getCompanyName(){ + return companyName; + } + + public static void setCompanyName(String companyName){ + Employee.companyName=companyName; + } + + public String getdepartment(){ + return this.department; + } + public double getSalary(){ + return this.salary; + } + public String getname(){ + return this.name; + } + public String getid(){ + return this.id; + } + + public void setId(String id){ + this.id=id; + } + public void setDepartment(String department){ + this.department=department; + } + public void setName(String name){ + this.name=name; + } + public void setSalary(double setsalary){ + if(setsalary>=2000.0){ + this.salary=setsalary; + } else{ + System.out.println("工资设置失败,自动设为2000元"); + this.salary=2000.0; + } + } + public void raiseSalary(double percent){ + if(percent>0.0){ + this.salary*=(1+percent/100.0); + } else { + System.out.println("输入有误"); + } + } + public void printInfo() { + System.out.println("公司名称: " + Employee.companyName); + System.out.println("员工ID: " + this.id); + System.out.println("姓名: " + this.name); + System.out.println("部门: " + this.department); + System.out.println("工资: " + this.salary); + System.out.println("--------------------"); + } + public static void main(String[] args){ + Employee employee1 = new Employee("E521","Mary","manager",30000); + Employee employee2 = new Employee("002", "李四", "市场部", 6000); + Employee.setCompanyName("思源股份有限公司"); + System.out.println("员工"+employee1.getname()+"的工资是"+employee1.getSalary()); + //员工Mary的工资是30000.0 + employee1.raiseSalary(10); + //调薪后员工Mary的工资是33000.0 + System.out.println("调薪后员工"+employee1.getname()+"的工资是"+employee1.getSalary()); + employee1.printInfo(); + employee2.printInfo(); + //工资设置失败 + employee1.setSalary(1000); + } +} \ No newline at end of file