用Java 定义并测试一个代表员工的Employee类。员工属性包括“编号”、“姓名”、“基本薪水”、“薪水增长额”;还包括 “计算增长后的工资总额”。
时间: 2023-11-04 20:06:05 浏览: 258
以下是一个可能的Employee类的实现:
```
public class Employee {
private int id;
private String name;
private double baseSalary;
private double raiseAmount;
public Employee(int id, String name, double baseSalary, double raiseAmount) {
this.id = id;
this.name = name;
this.baseSalary = baseSalary;
this.raiseAmount = raiseAmount;
}
public double getTotalSalary() {
return baseSalary + raiseAmount;
}
// Getters and setters for all properties
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBaseSalary() {
return baseSalary;
}
public void setBaseSalary(double baseSalary) {
this.baseSalary = baseSalary;
}
public double getRaiseAmount() {
return raiseAmount;
}
public void setRaiseAmount(double raiseAmount) {
this.raiseAmount = raiseAmount;
}
}
```
我们可以编写一个简单的测试程序来测试该类的功能:
```
public class EmployeeTest {
public static void main(String[] args) {
Employee john = new Employee(1, "John", 50000, 10000);
System.out.println("John's total salary is " + john.getTotalSalary());
}
}
```
该程序创建一个名为“John”的Employee对象,基本工资为50000,增长额为10000,并计算出他的总工资。输出应为:
```
John's total salary is 60000.0
```
阅读全文