校园角色类设计

学校需要构建综合系统,使用者包含多种角色。角色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();

}

}

输出格式:

我是张三,年龄32岁。工号是33006,2019年10月25日入职。是一名教师,讲师职称。

我是王五,年龄27岁。工号是32011,2015年6月17日入职。是一名教务员。

我是李四,年龄19岁。学号是20201103,来自202011班。

输出样例:

在这里给出相应的输出。例如:

我是张三,年龄32岁。工号是33006,2019年10月25日入职。是一名教师,讲师职称。

我是王五,年龄27岁。工号是32011,2015年6月17日入职。是一名教务员。

我是李四,年龄19岁。学号是20201103,来自202011班。

————————————————————————————————————————

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","6","17","教务员");

fac.show();

sta.show();

stu.show();

}

}

class Employee {

String name;

int age;

String gonghao;//工号

String nian;

String yue;

String ri;

Employee(String name,int age,String gonghao,String nian,String yue,String ri){

this.name=name;

this.age=age;

this.gonghao=gonghao;

this.nian=nian;

this.yue=yue;

this.ri=ri;

}

}

class Faculty extends Employee {

String teater;

Faculty(String name, int age, String gonghao, String nian, String yue, String ri,String teater) {

super(name, age, gonghao, nian, yue, ri);

this.teater=teater;

}

public void show() {

System.out.print("我是"+name+",年龄"+age+"岁。工号是"+gonghao+","+nian+"年"+yue+"月"+ri+"日入职。");

System.out.println("是一名教师,"+teater+"职称。");

}

}

class Staff extends Employee {

String jiao;//教务员

Staff(String name, int age, String gonghao, String nian, String yue, String ri, String jiao) {

super(name, age, gonghao, nian, yue, ri);

this.jiao=jiao;

}

public void show() {

System.out.print("我是"+name+",年龄"+age+"岁。工号是"+gonghao+","+nian+"年"+yue+"月"+ri+"日入职。");

System.out.println("是一名"+jiao+"。");

}

}

class Student {

String name;

int age;

String xuehao;

String banji;

Student(String name,int age, String xuehao,String banji){

this.age=age;

this.name=name;

this.xuehao=xuehao;

this.banji=banji;

}

public void show() {

System.out.println("我是"+name+",年龄"+age+"岁。学号是"+xuehao+",来自"+banji+"班。");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
```java import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; class Role { private String name; private int age; private String gender; public Role(String name, int age, String gender) { this.name = name; this.age = age; this.gender = gender; } public void show() { System.out.println("我是" + name + ",年龄" + age + "岁。"); } } class Student extends Role { private String stuNum; private String className; public Student(String name, int age, String stuNum, String className) { super(name, age, "男"); this.stuNum = stuNum; this.className = className; } public void show() { super.show(); System.out.println("学号是" + stuNum + ",来自" + className + "班。"); } } class Employee extends Role { private String workNum; private Date entryDate; public Employee(String name, int age, String workNum, String entryDate) throws ParseException { super(name, age, "女"); this.workNum = workNum; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); this.entryDate = sdf.parse(entryDate); } public void show() { super.show(); System.out.println("工号是" + workNum + "," + entryDate.getYear() + 1900 + "年" + (entryDate.getMonth() + 1) + "月" + entryDate.getDate() + "日入职。"); } } class Faculty extends Employee { private String title; public Faculty(String name, int age, String workNum, String entryDate, String title) throws ParseException { super(name, age, workNum, entryDate); this.title = title; } public void show() { super.show(); System.out.println("是一名教师," + title + "职称。"); } } class Staff extends Employee { private String position; public Staff(String name, int age, String workNum, String entryDate, String position) throws ParseException { super(name, age, workNum, entryDate); this.position = position; } public void show() { super.show(); System.out.println("是一名" + position + "。"); } } public class Main { public static void main(String[] args) throws ParseException { 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(); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值