Design a class named Person and its two subclasses named Student and Employee .Make Faculty and Staff subclasses of Employee . A person has a name,address, phonenumber, and email address. A student has a class status (freshman,sophomore,junior, or senior). Define the status as a constant. An employee has an office,salary, and date hired. A faculty member has office hours and a rank. A staffmember has a title. Override the toString method in each class to display the class name and the person’s name.
Write a test program that creates a Person , Student , Employee , Faculty , and Staff , and invokes their toString() methods.
public class Person {
String name;
String address;
String telphone;
public Person(String n,String a,String t)
{
name=n;
address=a;
telphone=t;
}
public String toString()
{
return name+" Person";
}
public void display(Person person)
{
System.out.println(person);
}
}
public class Employee extends Person{
String office;
double salary;
public Employee(String n,String a,String t,String o,double s)
{
super(n, a, t);
office = o;
salary = s;
}
public String toString()
{
return name+"employee";
}
}
public class Student extends Person{
final String class1="一年级";
final String class2="二年级";
final String class3="三年级";
final String class4="四年级";
public Student(String n,String a,String t)
{
super(n, a, t);
}
public String toString()
{
return name+" Student";
}
}
public class Faculty extends Employee{ int Level; public Faculty (String n,String a,String t,String o,double w,int level) { super(n, a, t, o, w); Level = Level; } public String toString() { return name+"Faculty"; } }
public class Staff extends Employee{ String position; public Staff(String n,String a,String t,String o,double w,String p) { super(n,a,t,o,w); position=p; } public String toString() { return name+"staff"; } }
public class Test { public static void main(String[] args) { Person p = new Person("网", "数据库的","2345678" ); p.display(p); Student s = new Student("王宏","河南省漯河市","15839652309"); s.display(s); Employee e = new Employee ("李四","河南省漯河市","0395112222","人事局",222.00); e.display(e); Faculty f = new Faculty("明明", "河北", "11232312", "帮手", 234,1); f.display(f); Staff sta = new Staff("红红","河南省周口市","13849472334","人事科",345.00,"副局长"); sta.display(sta); } }