使用【java】写【teacher类五个成员变量,姓名,性别,年龄,讲授课程,教学效果】的代码
时间: 2024-12-13 20:21:31 浏览: 2
在Java中,我们可以创建一个名为`Teacher`的类,包含五个成员变量,分别表示姓名、性别、年龄、讲授课程和教学效果。下面是一个简单的示例:
```java
public class Teacher {
// 成员变量
private String name; // 姓名
private String gender; // 性别
private int age; // 年龄
private String courseTaught; // 讲授课程
private double teachingEffectiveness; // 教学效果
// 构造函数
public Teacher(String name, String gender, int age, String courseTaught, double teachingEffectiveness) {
this.name = name;
this.gender = gender;
this.age = age;
this.courseTaught = courseTaught;
this.teachingEffectiveness = teachingEffectiveness;
}
// 提供getter和setter方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCourseTaught() {
return courseTaught;
}
public void setCourseTaught(String courseTaught) {
this.courseTaught = courseTaught;
}
public double getTeachingEffectiveness() {
return teachingEffectiveness;
}
public void setTeachingEffectiveness(double teachingEffectiveness) {
this.teachingEffectiveness = teachingEffectiveness;
}
}
```
阅读全文