1、(继承与多态)设计Person(人)、Student(学生)、Employee(雇员)、Faculty(教员)、Staff(职员)类,Student、Employee是Person的子类,Faculty、Staff是Employee的子类。所有人都有姓名、地址、电话号码、电子邮件地址。学生有班级状态:大一、大二、大三、大四,将这些状态定义为常量。一个雇员涉及办公室、工资、受聘日期(使用Date类对象)。教员有办公时间、级别。职员有职务称号。覆盖每个类的toString()方法,显示类别名称和姓名。画出这些类的UML图,实现上述要求,用主程序测试这些类并调用他们的toString()。注意:作业提交请将程序和UML放在一个word文档提交
package assignment;
import java.util.Date;
public class Person {
private String name;
private String address;
private String number;
private String Email;
protected Person() {
}
protected Person(String name,String address,String number, String Email) {
this.name = name;
this.address = address;
this.number = number;
this.Email = Email;
}
protected String getName() {
return name;
}
protected String getAddress() {
return address;
}
protected String getNumber() {
return number;
}
protected String getEmail() {
return Email;
}
public String toString() {
return "Person:"+getName()+" 详细信息如下"+toStringOfAllInformation();
}
public String toStringOfAllInformation() {
return "Name:"+getName()+"\nAddress:"+getAddress()+"\nNumber:"+getNumber()+"\nEmail:"+getEmail()+"\n";
}
}
class Student extends Person{
private String StudentState;
public Student() {
}
public Student(String StudentState,String name,String address,String number, String Email) {
super(name,address,number,Email);
this.StudentState = StudentState;
}
public String getStudentState() {
return StudentState;
}
public String toStringOfAllInformation() {
return "Name:"+getName()+"\nAddress:"+getAddress()+"\nNumber:"+getNumber()+"\nEmail:"+getEmail()+"\ngrade:"+getStudentState()+"\n";
}
@Override
public String toString() {
return "Student:"+getName()+" 详细信息如下"+toStringOfAllInformation();
}
}
class Employee extends Person{
private String Office;
private double salary;
private Date EntryDate;
protected Employee() {
}
protected Employee(String Office,double salary,String name,String address,String number, String Email,int year,int month,int day) {
super(name,address,number,Email);
this.Office = Office;
this.salary = salary;
this.EntryDate = new Date(year-1900,month-1,day);
}
protected String getOffice() {
return Office;
}
protected double getSalary() {
return salary;
}
protected Date getEntryDate() {
return EntryDate;
}
@Override
public String toString() {
return "Employee:"+getName()+" 详细信息如下"+toStringOfAllInformation();
}
public String toStringOfAllInformation() {
return "Name:"+getName()+"\nAddress:"+getAddress()+"\nNumber:"+getNumber()+"\nEmail:"+getEmail()+"\nSalary:"+getSalary()+"\nOffice:"+getOffice()+"\nEnterDate:"+getEntryDate()+"\n";
}
}
class Faculty extends Employee{
private String OfficeTime;
private String PostGrade;
public Faculty() {
}
public Faculty(String Office,double salary,String OfficeTime,String PostGrade,String name,String address,String number, String Email,int year,int month,int day) {
super(Office,salary,name,address,number,Email,year,month,day);
this.OfficeTime = OfficeTime;
this.PostGrade = PostGrade;
}
public String getOfficeTime() {
return OfficeTime;
}
public String getPostGrade() {
return PostGrade;
}
public String toStringOfAllInformation() {
return "Name:"+getName()+"\nAddress:"+getAddress()+"\nNumber:"+getNumber()+"\nEmail:"+getEmail()+"\nSalary:"+getSalary()+"\nOffice:"+getOffice()+"\nPostGrade:"+getPostGrade()+"\nOfficeTime:"+getOfficeTime()+"\nEnterDate:"+getEntryDate()+"\n";
}
@Override
public String toString() {
return "Faculty:"+getName()+" 详细信息如下"+toStringOfAllInformation();
}
}
class Staff extends Employee{
private String Post;
public Staff() {
}
public Staff(String Office,double salary,String Post,String name,String address,String number, String Email,int year,int month,int day) {
super(Office,salary,name,address,number,Email,year,month,day);
this.Post = Post;
}
public String getPost() {
return Post;
}
public String toStringOfAllInformation() {
return "Name:"+getName()+"\nAddress:"+getAddress()+"\nNumber:"+getNumber()+"\nEmail:"+getEmail()+"\nSalary:"+getSalary()+"\nOffice:"+getOffice()+"\nPost:"+getPost()+"\nEnterDate:"+getEntryDate()+"\n";
}
@Override
public String toString() {
return "Staff:"+getName()+" 详细信息如下"+toStringOfAllInformation();
}
}
package assignment;
public class testPerson {
public static void main(String[] args) {
// TODO Auto-generated method stub
Person a = new Person("小明","长沙","1852342","[email protected]");
System.out.println(a.toString());
Student a1 = new Student("大二","小红","长沙","18523342","[email protected]");
System.out.println(a1.toString());
Employee a2 = new Employee("济南",2000,"小强","长沙","1852342","[email protected]",2000,10,1);
System.out.println(a2.toString());
Faculty a3 = new Faculty("济南",2000,"9:00~21:00","高级","小赵","长沙","1852342","[email protected]",2000,10,1);
System.out.println(a3.toString());
Staff a4 = new Staff("济南",2000,"博客专家","小王","长沙","1852342","[email protected]",2000,10,1);
System.out.println(a4.toString());
}
}