【1】编写实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty和Staff。 具体要求如下: [1].Person类中的属性有:姓名name(String类型),地址address(String类型),电话号码telphone(String类型)和电子邮件地址email(String类型); [2].Employee类中的属性有:办公室office(String类型),工资wage(double类型),受雇日期hiredate(String类型); [3].Faculty类中的属性有:学位degree(String类型),级别level(String类型); Staff类中的属性有:职务称号duty(String类型)。
时间: 2023-05-28 21:01:07 浏览: 187
[4].Person类应该有一个无参的构造函数,一个带有全部属性的构造函数以及getters/setters方法;
[5].Employee类应该有一个无参的构造函数、一个带有全部属性的构造函数以及getters/setters方法;
[6].Faculty类应该有一个无参的构造函数、一个带有全部属性的构造函数以及getters/setters方法;
[7].Staff类应该有一个无参的构造函数、一个带有全部属性的构造函数以及getters/setters方法;
[8].Person类还应该有一个toString()方法,用于描述一个Person对象的信息;
[9].Employee类还应该有一个toString()方法,用于描述一个Employee对象的信息;
[10].Faculty类还应该有一个toString()方法,用于描述一个Faculty对象的信息;
[11].Staff类还应该有一个toString()方法,用于描述一个Staff对象的信息。
以下是代码实现:
```
public class Person {
private String name;
private String address;
private String telephone;
private String email;
public Person() {}
public Person(String name, String address, String telephone, String email) {
this.name = name;
this.address = address;
this.telephone = telephone;
this.email = email;
}
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 String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String toString() {
return "Name: " + this.getName() + ", Address: " + this.getAddress() + ", Telephone: " +
this.getTelephone() + ", Email: " + this.getEmail();
}
}
public class Employee extends Person {
private String office;
private double wage;
private String hiredate;
public Employee() {}
public Employee(String name, String address, String telephone, String email, String office, double wage, String hiredate) {
super(name, address, telephone, email);
this.office = office;
this.wage = wage;
this.hiredate = hiredate;
}
public String getOffice() {
return office;
}
public void setOffice(String office) {
this.office = office;
}
public double getWage() {
return wage;
}
public void setWage(double wage) {
this.wage = wage;
}
public String getHiredate() {
return hiredate;
}
public void setHiredate(String hiredate) {
this.hiredate = hiredate;
}
public String toString() {
return super.toString() + ", Office: " + this.getOffice() + ", Wage: " + this.getWage() + ", Hiredate: " + this.getHiredate();
}
}
public class Faculty extends Employee {
private String degree;
private String level;
public Faculty() {}
public Faculty(String name, String address, String telephone, String email, String office, double wage, String hiredate,
String degree, String level) {
super(name, address, telephone, email, office, wage, hiredate);
this.degree = degree;
this.level = level;
}
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String toString() {
return super.toString() + ", Degree: " + this.getDegree() + ", Level: " + this.getLevel();
}
}
public class Staff extends Employee {
private String duty;
public Staff() {}
public Staff(String name, String address, String telephone, String email, String office, double wage, String hiredate,
String duty) {
super(name, address, telephone, email, office, wage, hiredate);
this.duty = duty;
}
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public String toString() {
return super.toString() + ", Duty: " + this.getDuty();
}
}
```
阅读全文