写一个java程序,由Employee,Manager,secretary,technician,clerk组成,employee含有employee number,basic salary,getEmployeeNumber., get BasicSallary
时间: 2024-05-09 09:16:37 浏览: 96
一个java做的员工管理系统
下面是一个简单的Java程序,包含Employee、Manager、Secretary、Technician、Clerk这五个类,每个类都有employee number和basic salary属性,并实现了getEmployeeNumber和getBasicSalary方法:
```java
public class Employee {
private int employeeNumber;
private double basicSalary;
public int getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(int employeeNumber) {
this.employeeNumber = employeeNumber;
}
public double getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}
}
public class Manager extends Employee {}
public class Secretary extends Employee {}
public class Technician extends Employee {}
public class Clerk extends Employee {}
```
在这个程序中,Manager、Secretary、Technician、Clerk类都继承了Employee类,因为它们都是员工,都有相同的属性和方法。如果需要对每个类进行不同的操作,可以在子类中重写父类的方法。
下面是一个简单的测试代码,演示如何创建一个Employee对象并设置其属性值:
```java
public static void main(String[] args) {
Employee employee = new Employee();
employee.setEmployeeNumber(1001);
employee.setBasicSalary(10000.0);
System.out.println("Employee Number: " + employee.getEmployeeNumber());
System.out.println("Basic Salary: " + employee.getBasicSalary());
}
```
输出结果:
```
Employee Number: 1001
Basic Salary: 10000.0
```
阅读全文