
请教几个JAVA的问题 高手进
1:定义一个接口IPerson,封装一个方法:voidprint()//输出人员有关信息2:利用IPerson接口规范,定义一个类Teacher,表示某学校教师的最基本信...
1:定义一个接口IPerson,封装一个方法:
void print()//输出人员有关信息
2:利用IPerson接口规范,定义一个类Teacher,表示某学校教师的最基本信息。
4个成员变量:工号num,
姓名name,
工龄workAge,
职务job;
3个成员方法:
Teacher ( String num,
String name,
int workAge,
String job);
Teacher( String num,
double workAge);
输出教师的工号和工龄:print();
3:再定义一个类Director,表示教师中的主任。主任有专门的助理。
5个成员变量: 工号num,
姓名name,
工龄workAge,
职务job ,
助理名assistantName;
2个成员方法:
Director( String num,
String name,
int workAge,
String job,
String assistantName);
输出主任的工号和他的助理:print();
这几题的代码应该怎么打?我是个初学者 谢谢各位大大 展开
void print()//输出人员有关信息
2:利用IPerson接口规范,定义一个类Teacher,表示某学校教师的最基本信息。
4个成员变量:工号num,
姓名name,
工龄workAge,
职务job;
3个成员方法:
Teacher ( String num,
String name,
int workAge,
String job);
Teacher( String num,
double workAge);
输出教师的工号和工龄:print();
3:再定义一个类Director,表示教师中的主任。主任有专门的助理。
5个成员变量: 工号num,
姓名name,
工龄workAge,
职务job ,
助理名assistantName;
2个成员方法:
Director( String num,
String name,
int workAge,
String job,
String assistantName);
输出主任的工号和他的助理:print();
这几题的代码应该怎么打?我是个初学者 谢谢各位大大 展开
1个回答
展开全部
IPerson:
public interface IPerson {
void print();
}
Teacher:
public class Teacher implements IPerson {
private String num;
private String name;
private int workAge;
private String job;
public Teacher(String num, String name, int workAge, String job) {
this.num = num;
this.name = name;
this.workAge = workAge;
this.job = job;
}
public Teacher(String num, int workAge) {
this.num = num;
this.workAge = workAge;
}
public void print() {
System.out.println(this.name + "的工号是 :\t" + this.num + "\t年龄是 :\t" + this.workAge);
}
}
Director:
public class Director implements IPerson {
private String num;
private String name;
private int workAge;
private String job;
private String assistantName;
public Director(String num, String name, int workAge, String job,
String assistantName) {
this.num = num;
this.name = name;
this.workAge = workAge;
this.job = job;
this.assistantName = assistantName;
}
public void print() {
System.out.println(this.name + "的工号是 :\t" + this.num + "\t助手是 :\t" + this.assistantName);
}
}
Start: 用于测试,运行这个就可以看到效果
public class Start {
public static void main(String[] args) {
IPerson personT = new Teacher("TEACHER:001", "刘德华", 3, "数学老师");
IPerson personD = new Director("DIRECTOR:001", "周杰伦", 3, "教导主任", "蔡依琳");
personT.print();
personD.print();
}
}
public interface IPerson {
void print();
}
Teacher:
public class Teacher implements IPerson {
private String num;
private String name;
private int workAge;
private String job;
public Teacher(String num, String name, int workAge, String job) {
this.num = num;
this.name = name;
this.workAge = workAge;
this.job = job;
}
public Teacher(String num, int workAge) {
this.num = num;
this.workAge = workAge;
}
public void print() {
System.out.println(this.name + "的工号是 :\t" + this.num + "\t年龄是 :\t" + this.workAge);
}
}
Director:
public class Director implements IPerson {
private String num;
private String name;
private int workAge;
private String job;
private String assistantName;
public Director(String num, String name, int workAge, String job,
String assistantName) {
this.num = num;
this.name = name;
this.workAge = workAge;
this.job = job;
this.assistantName = assistantName;
}
public void print() {
System.out.println(this.name + "的工号是 :\t" + this.num + "\t助手是 :\t" + this.assistantName);
}
}
Start: 用于测试,运行这个就可以看到效果
public class Start {
public static void main(String[] args) {
IPerson personT = new Teacher("TEACHER:001", "刘德华", 3, "数学老师");
IPerson personD = new Director("DIRECTOR:001", "周杰伦", 3, "教导主任", "蔡依琳");
personT.print();
personD.print();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询