From 9fe103d807762e3a1dd46c67ebdef34d50e8a658 Mon Sep 17 00:00:00 2001 From: peisishuang <1767255628@qq.com> Date: Mon, 23 Mar 2026 19:08:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'w3'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AI协助记录 协助写测试代码 --- w3/Employee.java.txt | 43 ++++++++++++++++++++++++++++++++++++++++ w3/EmployeeTest.java.txt | 26 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 w3/Employee.java.txt create mode 100644 w3/EmployeeTest.java.txt diff --git a/w3/Employee.java.txt b/w3/Employee.java.txt new file mode 100644 index 0000000..436b416 --- /dev/null +++ b/w3/Employee.java.txt @@ -0,0 +1,43 @@ +public class Employee { + private String id; + private String name; + private String department; + private double salary; + private static final double Min=2000; + public Employee(String id,String name,String department,double salary) { + this.id = id; + this.name = name; + this.department = department; + if (salary >= Min) { + this.salary = salary; + } else { + this.salary = Min; + } + } + 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){ + this.salary=salary; + }else{ + this.salary=Min; + } + } + public void raiseSalary(double percent) { + if (percent < 0) { + System.out.println("本次涨薪无效"); + return; + } + double newSalary = this.salary * (1 + percent / 100); + if (newSalary >= Min) { + this.salary = newSalary; + } else { + this.salary = Min; + } + } +} diff --git a/w3/EmployeeTest.java.txt b/w3/EmployeeTest.java.txt new file mode 100644 index 0000000..7d43e75 --- /dev/null +++ b/w3/EmployeeTest.java.txt @@ -0,0 +1,26 @@ +public class EmployeeTest { + public static void main(String[] args){ + Employee yg1=new Employee("E001","张三","技术部",8000); + Employee yg2=new Employee("E002","李四","人事部",1800); + System.out.println("初始信息如下"); + System.out.println(yg1); + System.out.println(yg2); + + yg1.setName("张四"); + yg1.setDepartment("研发部"); + yg1.setSalary(9000); + yg2.setSalary(2500); + System.out.println("修改后如下"); + System.out.println(yg1); + System.out.println(yg2); + + System.out.println("涨薪测试"); + yg1.raiseSalary(10); + yg2.raiseSalary(5); + System.out.println(yg1); + System.out.println(yg2); + yg1.raiseSalary(-5); + System.out.println(yg1); + + } +}