Java创建一个教师类 包括teacherId, teacherName, teacherGender, teacherBirth, teacherPhone, courseName
时间: 2024-06-09 17:10:58 浏览: 153
可以使用以下代码创建一个教师类:
```java
public class Teacher {
private int teacherId;
private String teacherName;
private String teacherGender;
private Date teacherBirth;
private String teacherPhone;
private String courseName;
public Teacher(int teacherId, String teacherName, String teacherGender, Date teacherBirth, String teacherPhone, String courseName) {
this.teacherId = teacherId;
this.teacherName = teacherName;
this.teacherGender = teacherGender;
this.teacherBirth = teacherBirth;
this.teacherPhone = teacherPhone;
this.courseName = courseName;
}
public int getTeacherId() {
return teacherId;
}
public void setTeacherId(int teacherId) {
this.teacherId = teacherId;
}
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public String getTeacherGender() {
return teacherGender;
}
public void setTeacherGender(String teacherGender) {
this.teacherGender = teacherGender;
}
public Date getTeacherBirth() {
return teacherBirth;
}
public void setTeacherBirth(Date teacherBirth) {
this.teacherBirth = teacherBirth;
}
public String getTeacherPhone() {
return teacherPhone;
}
public void setTeacherPhone(String teacherPhone) {
this.teacherPhone = teacherPhone;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
}
```
在这个教师类中,我们定义了教师的基本属性,包括教师编号、姓名、性别、出生日期、联系电话、所教课程等。同时,也定义了相应的 getter 和 setter 方法,以方便对这些属性进行操作。
阅读全文