用Java设计一个Teacher类,最好有解释。
答案:1 悬赏:60 手机版
解决时间 2021-03-26 18:03
- 提问者网友:玫瑰园
- 2021-03-26 04:37
用Java设计一个Teacher类,最好有解释。
最佳答案
- 五星知识达人网友:酒安江南
- 2021-03-26 06:06
class Teacher{
private String Name;
private String TeacherID;
private String Address;
private String Course;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getTeacherID() {
return TeacherID;
}
public void setTeacherID(String teacherID) {
TeacherID = teacherID;
}
public String getAddress() {
return Address;
}
public void setAddress(String address) {
Address = address;
}
public String getCourse() {
return Course;
}
public void setCourse(String course) {
Course = course;
}
public String queryCourse(String qryString){
if(this.TeacherID.equals(qryString)){
System.out.println("Teacher:"+this.Name);
System.out.println("Course:"+this.Course);
return this.Course;
}else{
System.out.println("没有这个编号的老师");
return null;
}
}
}
public class Test {
public static void main(String[] args) {
Teacher t=new Teacher();
t.setAddress("Beijing");
t.setCourse("OS");
t.setName("Peter");
t.setTeacherID("001");
t.queryCourse("001");
t.queryCourse("002");
}
}
private String Name;
private String TeacherID;
private String Address;
private String Course;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getTeacherID() {
return TeacherID;
}
public void setTeacherID(String teacherID) {
TeacherID = teacherID;
}
public String getAddress() {
return Address;
}
public void setAddress(String address) {
Address = address;
}
public String getCourse() {
return Course;
}
public void setCourse(String course) {
Course = course;
}
public String queryCourse(String qryString){
if(this.TeacherID.equals(qryString)){
System.out.println("Teacher:"+this.Name);
System.out.println("Course:"+this.Course);
return this.Course;
}else{
System.out.println("没有这个编号的老师");
return null;
}
}
}
public class Test {
public static void main(String[] args) {
Teacher t=new Teacher();
t.setAddress("Beijing");
t.setCourse("OS");
t.setName("Peter");
t.setTeacherID("001");
t.queryCourse("001");
t.queryCourse("002");
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯