学校需要构建综合系统,使用者包含多种角色。角色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班。
时间: 2024-02-21 21:59:25 浏览: 187
Student-Faculty-Document-Sharing-API:该系统允许学生和教职员工共享有关学校活动,时间表和资源的信息
```
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class Person {
private String name;
private int age;
private String gender;
public Person(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public void show() {
System.out.println("我是" + name + ",年龄" + age + "岁。");
}
}
class Employee extends Person {
private String id;
private String hireDate;
public Employee(String name, int age, String id, String hireDate, String dateFormat) throws ParseException {
super(name, age, "未知");
this.id = id;
this.hireDate = formatDate(hireDate, dateFormat);
}
public void show() {
super.show();
System.out.println("工号是" + id + "," + hireDate + "入职。");
}
private String formatDate(String dateStr, String dateFormat) throws ParseException {
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdf2 = new SimpleDateFormat(dateFormat);
Date date = sdf1.parse(dateStr);
return sdf2.format(date);
}
}
class Faculty extends Employee {
private String title;
public Faculty(String name, int age, String id, String hireDate, String dateFormat, String title) throws ParseException {
super(name, age, id, hireDate, dateFormat);
this.title = title;
}
public void show() {
super.show();
System.out.println("是一名教师," + title + "职称。");
}
}
class Staff extends Employee {
private String jobTitle;
public Staff(String name, int age, String id, String hireDate, String dateFormat, String jobTitle) throws ParseException {
super(name, age, id, hireDate, dateFormat);
this.jobTitle = jobTitle;
}
public void show() {
super.show();
System.out.println("是一名" + jobTitle + "。");
}
}
class Student extends Person {
private String studentNo;
private String className;
public Student(String name, int age, String studentNo, String className) {
super(name, age, "未知");
this.studentNo = studentNo;
this.className = className;
}
public void show() {
super.show();
System.out.println("学号是" + studentNo + ",来自" + className + "班。");
}
}
public class Main {
public static void main(String[] args) throws ParseException {
Faculty fac = new Faculty("张三", 32, "33006", "20191025", "yyyy年M月d日", "讲师");
Student stu = new Student("李四", 19, "20201103", "202011");
Staff sta = new Staff("王五", 27, "32011", "20150617", "yyyy年M月d日", "教务员");
fac.show();
sta.show();
stu.show();
}
}
```
阅读全文