用Java 定义并测试一个代表员工的Employee类。员工属性包括“编号”、“姓名”、“基本薪水”、“薪水增长额”;还包括 “计算增长后的工资总额”。
时间: 2023-11-05 11:34:12 浏览: 35
public class Employee {
private int id;
private String name;
private double salary;
private double salaryIncrease;
public Employee(int id, String name, double salary, double salaryIncrease) {
this.id = id;
this.name = name;
this.salary = salary;
this.salaryIncrease = salaryIncrease;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public double getSalaryIncrease() {
return salaryIncrease;
}
public void setSalaryIncrease(double salaryIncrease) {
this.salaryIncrease = salaryIncrease;
}
public double getTotalSalary() {
return salary + salaryIncrease;
}
}
// 测试代码
public class EmployeeTest {
public static void main(String[] args) {
Employee employee = new Employee(1, "John Doe", 5000, 1000);
System.out.println("Employee ID: " + employee.getId());
System.out.println("Employee Name: " + employee.getName());
System.out.println("Employee Salary: " + employee.getSalary());
System.out.println("Employee Salary Increase: " + employee.getSalaryIncrease());
System.out.println("Employee Total Salary: " + employee.getTotalSalary());
employee.setSalaryIncrease(2000);
System.out.println("Employee Salary Increase: " + employee.getSalaryIncrease());
System.out.println("Employee Total Salary: " + employee.getTotalSalary());
}
}
阅读全文