回答时间不够了,先提交等会儿补上答案吧
1 接口
public interface ITeacher {
public void intro();
public void giveLesson();
}
2 Teachar 类
public class Teacher implements ITeacher {
private String name;
private int age;
public Teacher(){}
public Teacher(String name,int age){
this.name=name;
this.age=age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public void giveLesson() {
System.out.println("我给大家上课");
}
@Override
public void intro() {
System.out.println("我的名字是:"+name+"我今年"+age+"岁,给大家上课");
}
}
3 javaTeacher
public class JavaTeacher extends Teacher {
private String name;
private int age;
private String pro="java";
public JavaTeacher(){}
public JavaTeacher(String name,int age){
this.name=name;
this.age=age;
}
public JavaTeacher(String name,int age,String pro){
this(name,age);
this.pro=pro;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPro() {
return pro;
}
public void setPro(String pro) {
this.pro = pro;
}
@Override
public void giveLesson() {
System.out.println("我给大家上"+pro+"课");
}
@Override
public void intro() {
System.out.println("我的名字是:"+name+"我今年"+age+"岁!");
}
}
4 DBTeacher
public class DBTeacher extends Teacher {
private String name;
private int age;
private String pro="java";
public DBTeacher(){}
public DBTeacher(String name,int age){
this.name=name;
this.age=age;
}
public DBTeacher(String name,int age,String pro){
this(name,age);
this.pro=pro;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPro() {
return pro;
}
public void setPro(String pro) {
this.pro = pro;
}
@Override
public void giveLesson() {
System.out.println("我给大家上"+pro+"课");
}
@Override
public void intro() {
System.out.println("我的名字是:"+name+"我今年"+age+"岁!");
}
}
5. School
public class School {
private ITeacher t;
public School(){}
public School(ITeacher t){
this.t=t;
}
public void judge(){
System.out.println("请老师自我介绍");
t.intro();
System.out.println("请老师试讲");
t.giveLesson();
}
}
只是写类和接口啊?没有涉及到逻辑处理啊!
站位的那哥们帮你就可以了!!呵呵!!
public class Teacher {
protected String name;
protected int age;
protected String pro;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @return the pro
*/
public String getPro() {
return pro;
}
/**
* @param pro the pro to set
*/
public void setPro(String pro) {
this.pro = pro;
}
/**
* @param age
* the age to set
*/
public void setAge(int age) {
this.age = age;
}
public String intro() {
return "我是:" + this.name;
}
public String giveLesson() {
return "我在授课";
}
}
public class DBTeacher extends Teacher {
private String pro = "DB";
/*
* (non-Javadoc)
*
* @see com.magus.test1.Teacher#giveLesson()
*/
@Override
public String giveLesson() {
return "我在上" + pro + "课";
}
}
public class JavaTeacher extends Teacher {
private String pro = "java";
/*
* (non-Javadoc)
*
* @see com.magus.test1.Teacher#giveLesson()
*/
@Override
public String giveLesson() {
return "我在上" + pro + "课";
}
}
public class School {
public void judge(Teacher teacher) {
System.out.println(teacher.getAge() + "岁的" + teacher.getName() + "老师,传授的"
+ teacher.getPro() + "很不错");
}
}
import org.junit.Test;
public class SchoolTest {
@Test
public void testJudge() {
JavaTeacher java = new JavaTeacher();
java.setName("tom");
java.setAge(50);
java.setPro("Java");
System.out.println(java.intro());
System.out.println(java.giveLesson());
DBTeacher db = new DBTeacher();
db.setName("jim");
db.setAge(45);
db.setPro("DB");
System.out.println(db.intro());
System.out.println(db.giveLesson());
School sc = new School();
sc.judge(db);
sc.judge(java);
}
}