Bootstrap

PTA 校园角色类设计-1 JAVA

学校需要构建综合系统,使用者包含多种角色。角色Role分两类:学生Student和雇员Employee;雇员又分为教员Faculty和职员Staff。 每个角色都有姓名、性别。学生有学号、班级。一个雇员有工号、入职日期。教员有职称。职员有职位称号。 请以如下Main类为基础,构建各个角色类,将代码补充完整。

public class Main {
    public static void main(String[] args) {
        Faculty fac = new Faculty("张三",32,"33006","2019","10","25","讲师");
        Student stu=new Student("李四",19,"20201103","202011");
        Staff sta = new Staff("王五",27,"32011","2015","06","17","教务员");        
        fac.show();
        sta.show();
        stu.show();
    }
}
import java.util.Arrays;
import java.util.Scanner;

class Role{
    String name;
    int age;

    Role(String name, int age){
        this.name = name;
        this.age = age;
    }
}

class Faculty extends Role{
    private String id;
    private String f_name;

    private String year;
    private String month;
    private String day;

    Faculty(String name, int age, String id, String year, String month, String day, String f_name){
        super(name, age);
        this.id = id;
        this.year = year;
        this.month = month;
        this.day = day;
        this.f_name = f_name;
    }

    public void show(){
        System.out.println("我是" + super.name + ",年龄" + super.age + "岁。工号是" + this.id + "," + this.year + "年" + Integer.parseInt(this.month) + "月" + Integer.parseInt(this.day) + "日入职。是一名教师," + this.f_name + "职称。");
    }
}

class Student extends Role{
    private String id;
    private String cl;

    Student(String name, int age, String id, String cl){
        super(name, age);
        this.cl = cl;
        this.id = id;
    }

    public void show(){
        System.out.println("我是" + super.name + ",年龄" + age + "岁。学号是" + id + ",来自" + cl + "班。");
    }
}

class Staff extends Role{
    private String id;
    private String f_name;

    private String year;
    private String month;
    private String day;

    Staff(String name, int age, String id, String year, String month, String day, String f_name){
        super(name, age);
        this.id = id;
        this.year = year;
        this.month = month;
        this.day = day;
        this.f_name = f_name;
    }

    public void show(){
        System.out.println("我是" + super.name + ",年龄" + super.age + "岁。工号是" + this.id + "," + this.year + "年" + Integer.parseInt(this.month) + "月" + Integer.parseInt(this.day) + "日入职。是一名" + this.f_name + "。");
    }
}

public class Main {
    public static void main(String[] args) {
        Faculty fac = new Faculty("张三",32,"33006","2019","10","25","讲师");
        Student stu=new Student("李四",19,"20201103","202011");
        Staff sta = new Staff("王五",27,"32011","2015","06","17","教务员");
        fac.show();
        sta.show();
        stu.show();
    }
}
;