JAVA一个设计一个名为Person类和它的两个名为Student,Employee的子类

(Person,Student,Employee,Faculty,Staff类)设计一个名为Person类和它的两个名为Student,Employee的子类。Employee类又有子类:教员类Faculty和Staff类。每个人都有姓名,地址,电话号码和电子邮件地址,学生有班级状态(大一,大二,大三,大四),将这些状态定义为常量。一个雇员涉及办公室,工资。教员有办公时间和级别。职员有职务和称号。覆盖每个类中的toString方法,显示相应的类别名和人名。
编写一个测试程序,创建Person,Student,Employee,Faculty,Staff并且调用它们的toString()方法。还有一个小时要交作业了,很急

Person.java

public class Person {
private String name;
private String address;
private int phoneNumber;
private String email;

public Person(String name, String address, int phoneNumber, String email) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
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 int getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(int phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Override
public String toString() {
String result = "";
result = "Your name: " + name + "\n address: " + address + "\n phoneNumber: " + phoneNumber + "\n Email: "
+ email;
return result;
}
}

Student.java

public class Student extends Person{
public static final String FRESHER = "FRESHER";
public static final String SOPOMORE = "SOPOMORE";
public static final String JUNIOR = "JUNIOR";
public static final String SENIOR = "SENIOR";

private String status;

public Student(String name, String address, int phoneNumber, String email, String status) {
super(name, address, phoneNumber, email);
this.status = status;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

@Override
public String toString() {
String result = "";
result = "Your name: " + getName() + "\n address: " + getAddress() + "\n phoneNumber: " + getPhoneNumber() + "\n Email: "
+ getEmail() + "\nStatus: " + status;
return result;
}
}

Employee.java

public class Employee extends Person{
private String office;
private double salary;

public Employee(String name, String address, int phoneNumber, String email, String office, double salary) {
super(name, address, phoneNumber, email);
this.office = office;
this.salary = salary;
}

public String getOffice() {
return office;
}

public void setOffice(String office) {
this.office = office;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

@Override
public String toString() {
String result = "";
result = "Your name: " + getName() + "\n address: " + getAddress() + "\n phoneNumber: " + getPhoneNumber() + "\n Email: "
+ getEmail() + "Salary: " + salary + "\n Office: " + office;
return result;
}
}

Faculty.java

public class Faculty extends Employee {
private double officeHour;
private String grade;

public Faculty(String name, String address, int phoneNumber, String email, String office, double salary,
double officeHour, String grade) {
super(name, address, phoneNumber, email, office, salary);
this.setOfficeHour(officeHour);
this.setGrade(grade);
}

public String getGrade() {
return grade;
}

public void setGrade(String grade) {
this.grade = grade;
}

public double getOfficeHour() {
return officeHour;
}

public void setOfficeHour(double officeHour) {
this.officeHour = officeHour;
}

public String toString() {
String result = "";
result = "Your name: " + getName() + "\n address: " + getAddress() + "\n phoneNumber: " + getPhoneNumber()
+ "\n Email: " + getEmail() + "\n Salary: " + getSalary() + "\n Office: " + getOffice() + "\n Grade: "
+ grade + "\n OfficeHour: " + officeHour;
return result;
}
}

Staff.java

public class Staff extends Employee{
private String area;
private String position;

public Staff(String name, String address, int phoneNumber, String email, String office, double salary, String area, String position) {
super(name, address, phoneNumber, email, office, salary);
this.area = area;
this.position = position;
}

public String getArea() {
return area;
}

public void setArea(String area) {
this.area = area;
}

public String getPosition() {
return position;
}

public void setPosition(String position) {
this.position = position;
}

public String toString() {
String result = "";
result = "Your name: " + getName() + "\n address: " + getAddress() + "\n phoneNumber: " + getPhoneNumber() + "\n Email: "
+ getEmail() + "\nArea: " + area + "\n Position: " + position;
return result;
}
}

Main.java

public class Main {

public static void main(String[] args) {
Person person = new Person("Cici", "google", 123456, "[email protected]");
System.out.println(person);
System.out.println("------------------------------------");
Person student = new Student("XIXI", "baidu", 123456, "[email protected]", Student.FRESHER);
System.out.println(student);
Employee employee = new Employee("Cici", "google", 123456, "[email protected]", "A5", 2000.0);
System.out.println(employee);
System.out.println("------------------------------------");
Faculty faculty = new Faculty("Cici", "google", 123456, "[email protected]", "A5", 2000.0, 7.5, "Professor");
System.out.println(faculty);
System.out.println("------------------------------------");
Staff staff = new Staff("Cici", "google", 123456, "[email protected]", "A5", 2000.0, "Administrator", "Miss");
System.out.println(staff);
System.out.println("------------------------------------");
}
}


输出结果

Your name: Cici

address: google

phoneNumber: 123456

Email: [email protected]

------------------------------------

Your name: XIXI

address: baidu

phoneNumber: 123456

Email: [email protected]

Status: FRESHER

Your name: Cici

address: google

phoneNumber: 123456

Email: [email protected]: 2000.0

Office: A5

------------------------------------

Your name: Cici

address: google

phoneNumber: 123456

Email: [email protected]

Salary: 2000.0

Office: A5

Grade: Professor

OfficeHour: 7.5

------------------------------------

Your name: Cici

address: google

phoneNumber: 123456

Email: [email protected]

Area: Administrator

Position: Miss

------------------------------------


温馨提示:答案为网友推荐,仅供参考