定义Staff类(职工),添加如下属性(name, address, age, sex, salary, dateHired),类型自定,其中salary为工资,dateHired为雇佣日期(java.util.Date类型)。生成相应的setter/getter方法。 (2)编写Teacher类(教师),继承自Staff类,包含属性:department(系), speciality(专业), postAllowance(岗位津贴)。 (3)编写SecurityGuard类(保安),继承自Staff
时间: 2023-05-29 08:07:46 浏览: 146
java代码-定义一个员工信息类Employee,使用ArrayList对员工信息进行添加和显示
5星 · 资源好评率100%
类,包含属性:level(级别),workHours(工作时长)。
代码如下:
```
import java.util.Date;
public class Staff {
private String name;
private String address;
private int age;
private String sex;
private double salary;
private Date dateHired;
public Staff(String name, String address, int age, String sex, double salary, Date dateHired) {
this.name = name;
this.address = address;
this.age = age;
this.sex = sex;
this.salary = salary;
this.dateHired = dateHired;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public Date getDateHired() {
return dateHired;
}
public void setDateHired(Date dateHired) {
this.dateHired = dateHired;
}
}
public class Teacher extends Staff {
private String department;
private String speciality;
private double postAllowance;
public Teacher(String name, String address, int age, String sex, double salary, Date dateHired, String department, String speciality, double postAllowance) {
super(name, address, age, sex, salary, dateHired);
this.department = department;
this.speciality = speciality;
this.postAllowance = postAllowance;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getSpeciality() {
return speciality;
}
public void setSpeciality(String speciality) {
this.speciality = speciality;
}
public double getPostAllowance() {
return postAllowance;
}
public void setPostAllowance(double postAllowance) {
this.postAllowance = postAllowance;
}
}
public class SecurityGuard extends Staff {
private int level;
private int workHours;
public SecurityGuard(String name, String address, int age, String sex, double salary, Date dateHired, int level, int workHours) {
super(name, address, age, sex, salary, dateHired);
this.level = level;
this.workHours = workHours;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getWorkHours() {
return workHours;
}
public void setWorkHours(int workHours) {
this.workHours = workHours;
}
}
```
阅读全文