(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two

** (The Person, Student, Employee, Faculty, and Staff classes) 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, phone number, 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. Use the MyDate class defined in Programming Exercise 10.14 to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name.
Draw the UML diagram for the classes and implement them. Write a test pro- gram that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.

**
这里的每个子类要用super的显式去给其父类的变量赋值

package Chapter11;


import java.util.*;

public class Person11_2 {
    String name;
    String address;
    String phone_number;
    String email_address;

    public Person11_2() {

    }
    public Person11_2(
            String n, String a, String p, String e) {
        name = n;
        address = a;
        phone_number = p;
        email_address = e;
    }

    public String toString() {
        return  name + " Person";
    }
}


class Student0 extends Person11_2 {
    final String status1 = "Freshman";
    final String status2 = "Sophomore";
    final String status3 = "Junior";
    final String status4 = "Senior";
    public Student0(String n, String a, String p, String e) {
        super(n, a, p, e);
    }

    public String toString() {
        return name + " Student";
    }



}

class Employee0 extends Person11_2 {
    String office;
    double salary;
    Date date_hired = new Date();
    public Employee0(
            String n, String a, String p, String e, String o, double s) {
        super(n, a, p, e);
        this.office = o;
        this.salary = s;
    }

    public String toString() {
        return name + " Employee";
    }

}

class Faculty0 extends Employee0 {

    double work_hour;
    String rank;
    public Faculty0(
            String n, String a, String p, String e, String o, double s, double w, String r) {
        super(n, a, p, e, o, s);
        this.work_hour = w;
        this.rank = r;
    }

    public String toString() {
        return name + " Faculty";
    }

}
class Staff0 extends Employee0 {
    String title;

    public Staff0(String n, String a, String p, String e, String o, double s, String t) {
        super(n, a, p, e, o, s);
        title = t;
    }

    public String toString() {
        return name + " Staff";
    }

}
package Chapter11;

public class Test {
    public static void main(String[] args) {
        Person11_2 p = new Person11_2("张三", "北京", "98720349", "2292018@qq.com");
        System.out.println(p.toString());

        Student0 s = new Student0("李四", "上海", "15153894", "2121678@163.com");
        System.out.println(s.toString());

        Employee0 e = new Employee0(
                "王五", "广州", "5467890", "78976@qq.com","room101", 399999);
        System.out.println(e.toString());

        Faculty0 f = new Faculty0(
                "赵六", "深圳", "45678", "48500@qq.com",
                "room201",1000000, 8, "leader");
        System.out.println(f.toString());

        Staff0 sta = new Staff0(
                "钱七", "9990874", "467547489", "7489@qq.com",
                "room001", 29000, "monitor");
        System.out.println(sta.toString());

    }
}

这是测试的结果

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值