题目如下:在学校的人事管理系统中,教师与学生共同拥有的信息为,编号、姓名、性别、出生日期等;教师特有的信息为所在部门、职称、工资等;学生特有信息为高考分数、所学专业,将教师与学生共同拥有的部分,定义为人员类PersonClass(作为父类),并在此基础上定义教师类TercharClass和学生类StudentClass两个子类。将父类PersonClass修改为接口,在子类教师类TercharClass和学生类StudentClass中实现接口。编写含main函数的主类,测试接口。请主意是测试接口,请写出代码
时间: 2024-03-01 14:53:20 浏览: 97
web课程设计-人事信息管理系统
4星 · 用户满意度95%
以下是Java代码示例:
```java
// 定义PersonClass接口
interface PersonClass {
public int getID(); // 获取编号
public String getName(); // 获取姓名
public String getGender(); // 获取性别
public String getBirthDate(); // 获取出生日期
}
// 定义TercharClass类,实现PersonClass接口
class TercharClass implements PersonClass {
private int id;
private String name;
private String gender;
private String birthDate;
private String department;
private String jobTitle;
private int salary;
public TercharClass(int id, String name, String gender, String birthDate,
String department, String jobTitle, int salary) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthDate = birthDate;
this.department = department;
this.jobTitle = jobTitle;
this.salary = salary;
}
// 实现PersonClass接口中的方法
public int getID() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public String getBirthDate() {
return birthDate;
}
// 获取所在部门
public String getDepartment() {
return department;
}
// 获取职称
public String getJobTitle() {
return jobTitle;
}
// 获取工资
public int getSalary() {
return salary;
}
}
// 定义StudentClass类,实现PersonClass接口
class StudentClass implements PersonClass {
private int id;
private String name;
private String gender;
private String birthDate;
private int examScore;
private String major;
public StudentClass(int id, String name, String gender, String birthDate,
int examScore, String major) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthDate = birthDate;
this.examScore = examScore;
this.major = major;
}
// 实现PersonClass接口中的方法
public int getID() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public String getBirthDate() {
return birthDate;
}
// 获取高考分数
public int getExamScore() {
return examScore;
}
// 获取所学专业
public String getMajor() {
return major;
}
}
// 测试接口的主类
public class TestInterface {
public static void main(String[] args) {
// 创建一个教师对象
TercharClass teacher = new TercharClass(1001, "张三", "男", "1980-01-01",
"计算机科学与技术", "教授", 10000);
// 创建一个学生对象
StudentClass student = new StudentClass(2001, "李四", "女", "2000-01-01",
600, "软件工程");
// 调用接口中的方法获取共同信息
System.out.println("教师编号:" + teacher.getID());
System.out.println("教师姓名:" + teacher.getName());
System.out.println("教师性别:" + teacher.getGender());
System.out.println("教师出生日期:" + teacher.getBirthDate());
System.out.println("学生编号:" + student.getID());
System.out.println("学生姓名:" + student.getName());
System.out.println("学生性别:" + student.getGender());
System.out.println("学生出生日期:" + student.getBirthDate());
// 调用教师类特有的方法
System.out.println("教师所在部门:" + teacher.getDepartment());
System.out.println("教师职称:" + teacher.getJobTitle());
System.out.println("教师工资:" + teacher.getSalary());
// 调用学生类特有的方法
System.out.println("学生高考分数:" + student.getExamScore());
System.out.println("学生所学专业:" + student.getMajor());
}
}
```
阅读全文