用Java设计一个教师类,教师信息有身份证号,教师号,专业,姓名,性别,年龄,及授课的学时数。创建教师类的对象并输出对象的信息。
时间: 2023-07-16 11:15:37 浏览: 131
行业文档-设计装置-教师用授课代步车.zip
以下是用Java设计的教师类:
```java
public class Teacher {
private String idCardNo; // 身份证号
private String teacherNo; // 教师号
private String major; // 专业
private String name; // 姓名
private String gender; // 性别
private int age; // 年龄
private int teachingHours; // 授课的学时数
public Teacher(String idCardNo, String teacherNo, String major, String name, String gender, int age, int teachingHours) {
this.idCardNo = idCardNo;
this.teacherNo = teacherNo;
this.major = major;
this.name = name;
this.gender = gender;
this.age = age;
this.teachingHours = teachingHours;
}
public String getIdCardNo() {
return idCardNo;
}
public String getTeacherNo() {
return teacherNo;
}
public String getMajor() {
return major;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public int getTeachingHours() {
return teachingHours;
}
public void setIdCardNo(String idCardNo) {
this.idCardNo = idCardNo;
}
public void setTeacherNo(String teacherNo) {
this.teacherNo = teacherNo;
}
public void setMajor(String major) {
this.major = major;
}
public void setName(String name) {
this.name = name;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setAge(int age) {
this.age = age;
}
public void setTeachingHours(int teachingHours) {
this.teachingHours = teachingHours;
}
@Override
public String toString() {
return "Teacher{" +
"idCardNo='" + idCardNo + '\'' +
", teacherNo='" + teacherNo + '\'' +
", major='" + major + '\'' +
", name='" + name + '\'' +
", gender='" + gender + '\'' +
", age=" + age +
", teachingHours=" + teachingHours +
'}';
}
}
```
以下是创建教师类的对象并输出对象的信息的示例代码:
```java
public class Main {
public static void main(String[] args) {
Teacher teacher = new Teacher("1234567890", "T001", "计算机科学与技术", "张三", "男", 30, 40);
System.out.println(teacher.toString());
}
}
```
输出结果:
```
Teacher{idCardNo='1234567890', teacherNo='T001', major='计算机科学与技术', name='张三', gender='男', age=30, teachingHours=40}
```
阅读全文