(Person,Student,Employee,Faculty和Staff类)设计一个名为Person的类及两个名为S土地net和Employee的子类。Employee类又有子类:教员类Faculty和职员类Staff。每个人都有姓名,地址,电话号码和电子邮件地址。学生有班级状态(大一,大二,大三,大四)。将这些状态定义为常量。一个雇员涉及办公室,工资和受聘日期。使用编程练习题10.14中定义的MyDate类为受聘日期创建一个对象。教员有办公时间和级别。职员有头衔。重写每个类小红的toString()方法,显示相应的类名和人名.
//MyDate.java
package demo2;
import java.util.*;
public class MyDate {
private int year;
private int month;
private int day;
MyDate()
{
GregorianCalendar mydate = new GregorianCalendar();
year=mydate.get(Calendar.YEAR);
month=mydate.get(Calendar.MONTH);
day=mydate.get(Calendar.DAY_OF_MONTH);
}
MyDate(long elapsedTime)
{
GregorianCalendar date = new GregorianCalendar();
date.setTimeInMillis(elapsedTime);
year = date.get(Calendar.YEAR);
month = date.get(Calendar.MONTH);
day = date.get(Calendar.DAY_OF_MONTH);
}
public MyDate(int year,int month,int day)
{
this.year=year;
this.month=month;
this.day=day;
}
public int getYear()
{
return year;
}
public int getMonth()
{
return month;
}
public int getDay()
{
return day;
}
public void setYear(int year)
{
this.year=year;
}
public void setMonth(int month)
{
this.month=month;
}
public void setDay(int day)
{
this.day=day;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyDate mydate=new MyDate();
System.out.println(mydate.getYear()+"年"+mydate.getMonth()+"月"+mydate.getDay()+"日");
mydate=new MyDate(34355555133101L);
System.out.println(mydate.getYear()+"年"+mydate.getMonth()+"月"+mydate.getDay()+"日");
}
}
//Person
package demo2;
public class Person
{
protected String name;
protected String address;
protected String phone;
protected String email;
Person()
{
}
Person(String name,String address,String phone,String email)
{
this.name=name;
this.address=address;
this.phone=phone;
this.email=email;
}
public String toString()
{
return "Person";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//Student
package demo2;
public class Student extends Person
{
public static final String FRESHMAN = "大一";
public static final String SOPHOMORE = "大二";
public static final String JUNIOR = "大三";
public static final String SENIOR = "大四";
protected String status;
public String toString()
{
return "Student "+name;
}
Student(String name,String address,String phone,String email,String status)
{
super(name,address,phone,email);
this.status=status;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//Employee
package demo2;
import demo.MyDate;
public class Employee extends Person
{
protected String office;
protected double salary;
protected MyDate date;
public String toString()
{
return "Employee "+name;
}
Employee(String name,String address,String phone,String email,Stringoffice,double salary,MyDate date)
{
super(name,address,phone,email);
this.office=office;
this.salary=salary;
this.date=date;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//Faculty
package demo2;
import demo.MyDate;
public class Faculty extends Employee
{
protected String worktime;
protected String grade;
public String toString()
{
return "Faculty "+name;
}
Faculty(String name,String address,String phone,String email,String office,double salary,MyDate mydate,String worktime,String grade)
{
super(name,address,phone,email,office,salary,mydate);
this.worktime=worktime;
this.grade=grade;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//Staff
package demo2;
import demo.MyDate;
public class Staff extends Employee
{
protected String title;
public String toString()
{
return "Staff "+name;
}
Staff(String name,String address,String phone,String email,Stringoffice,double salary,MyDate mydate,String title)
{
super(name,address,phone,email,office,salary,mydate);
this.title=title;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
//PersonMain
package demo2;
import demo.MyDate;
public class PersonMain {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyDate mydate=new MyDate(2018,10,20);
Student student=new Student("张鹤","长沙","15277945665","[email protected]",Student.SOPHOMORE);
Employee employee=new Employee("李涵","湖南株洲","32456165","[email protected]","文科楼B210",6500,mydate);
Faculty faculty=new Faculty("吴丽","广西南宁","1314211556","[email protected]","理科楼A102",5000,mydate,"09:00~16:00","professor");
Staff staff=new Staff("孙昊","湖北武汉","1321335465","[email protected]","理科楼11",4500,mydate,"professor");
System.out.println(student.toString());
System.out.println(employee.toString());
System.out.println(faculty.toString());
System.out.println(staff.toString());
}
}