PTA 校园角色类设计-2 JAVA

在校园角色类设计-1题的基础上,增加了部分要求,加粗部分为增加的内容: 学校需要构建综合系统,使用者包含多种角色。角色Role分两类:学生Student和雇员Employee;雇员又分为教员Faculty和职员Staff。 每个角色都有姓名、年龄、性别、电话号码。学生有学号、班级、班级职务(班长、副班长、学习委员等)。一个雇员有工号、入职日期、所在部门。教员有职称和专业。职员有职位称号。 请以如下Main类为基础,构建各个角色类,将代码补充完整。 public class Main { public static void main(String[] args) { // TODO Auto-generated method stub 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.setSex(‘男’); fac.setTel(“13600770077”); fac.setDepartment(“数信学院”); fac.setMajor(“数学”); stu.setSex(‘女’); stu.setTel(“18000009999”); stu.setPosition(“班长”); sta.setSex(‘男’); sta.setTel(“18966666666”); sta.setDepartment(“航制学院”); Scanner input = new Scanner(System.in); int i = input.nextInt(); /* 使用多态根据用户的输入,输出不同的角色人物的信息, 输入1:教员 输入2:学生 输入3:职员 其他输入:输出"Wrong Format" */ } }

import java.util.Arrays;
import java.util.Scanner;class Role{String name;int age;char sex;String tel;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;private String department;private String major;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 + "," + this.sex +  ",年龄" + super.age + "岁。电话是" + super.tel +  "。工号是" + this.id + "," + this.year + "年" + Integer.parseInt(this.month) + "月" + Integer.parseInt(this.day) + "日入职。" + "就职于"+ this.department + "。是一名教师," +  this.major + "专业," + this.f_name + "职称。");}public void setTel(String tel) {super.tel = tel;}public void setDepartment(String department) {this.department = department;}public void setMajor(String major) {this.major = major;}public void setSex(char sex) {super.sex = sex;}
}class Student extends Role{private String id;private String cl;private String position;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 + "," + this.sex +  ",年龄" + super.age + "岁。电话是" + super.tel + "。学号是" + id + ",来自" + cl + "班。" + "担任" + this.position + "职务。");}public void setPosition(String position) {this.position = position;}public void setSex(char sex){super.sex = sex;}public void setTel(String tel){super.tel = tel;}
}class Staff extends Role{private String id;private String f_name;private String year;private String month;private String day;private String department;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 + "," + this.sex +  ",年龄" + super.age + "岁。电话是" + super.tel + "。工号是" + this.id + "," + this.year + "年" + Integer.parseInt(this.month) + "月" + Integer.parseInt(this.day) + "日入职。就职于" + this.department + "。是一名" + this.f_name + "。");}public void setDepartment(String department) {this.department = department;}public void setSex(char sex){super.sex = sex;}public void setTel(String tel){super.tel = tel;}
}public class Main { public static void main(String[] args) { // TODO Auto-generated method stubFaculty 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.setSex('男');fac.setTel("13600770077");fac.setDepartment("数信学院");fac.setMajor("数学");stu.setSex('女');stu.setTel("18000009999");stu.setPosition("班长");sta.setSex('男');sta.setTel("18966666666");sta.setDepartment("航制学院");Scanner input = new Scanner(System.in);int i = input.nextInt(); /* 使用多态根据用户的输入,输出不同的角色人物的信息, 输入1:教员 输入2:学生 输入3:职员 其他输入:输出"Wrong Format" */if(i == 1){fac.show();}else if(i == 2){stu.show();}else if(i == 3){sta.show();}else{System.out.println("Wrong Format");}
} }


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部