1.定义说英语接口
package 运动员和教练;
public interface SpeakEnglish {
public abstract void speak();
}
2.定义抽象人类
package 运动员和教练;
public abstract class Person {
private String name;
private String age;
public Person() {
}
public Person(String name, String age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public abstract void eat();
}
3.定义抽象教练类
package 运动员和教练;
public abstract class Instructor extends Person{
public Instructor() {
}
public Instructor(String name, String age) {
super(name, age);
}
public abstract void teach();
}
4.定义抽象运动员类
package 运动员和教练;
public abstract class Jock extends Person{
public Jock() {
}
public Jock(String name, String age) {
super(name, age);
}
public abstract void study();
}
5.定义具体篮球教练类
package 运动员和教练;
public class BasketballCoach extends Instructor{
public BasketballCoach() {
}
public BasketballCoach(String name, String age) {
super(name, age);
}
@Override
public void eat() {
System.out.println("花生米饭、肉末茄子、葱花土豆泥、鸭子海带汤。");
}
@Override
public void teach() {
System.out.println("教学员打篮球");
}
}
6.定义具体乒乓球教练员类
package 运动员和教练;
public class TableTennisCoach extends Instructor implements SpeakEnglish{
public TableTennisCoach() {
}
public TableTennisCoach(String name, String age) {
super(name, age);
}
@Override
public void eat() {
System.out.println("荞麦大米饭、香菇菜心、糖醋带鱼、豆腐血旺、丝瓜汤");
}
@Override
public void teach() {
System.out.println("教学员打乒乓球");
}
@Override
public void speak() {
System.out.println("讲英语");
}
}
7.定义篮球运动员类
package 运动员和教练;
public class basketballPlayer extends Jock{
public basketballPlayer() {
}
public basketballPlayer(String name, String age) {
super(name, age);
}
@Override
public void eat() {
System.out.println("两米饭(大米、小米)、五香鱼、五彩银丝胡萝卜、莴笋、鸡 腿菇木耳猪肝汤。");
}
@Override
public void study() {
System.out.println("学习打篮球");
}
}
8.定义乒乓球运动员类
package 运动员和教练;
public class TableTennisPlayer extends Jock implements SpeakEnglish{
public TableTennisPlayer() {
}
public TableTennisPlayer(String name, String age) {
super(name, age);
}
@Override
public void eat() {
System.out.println("金银饭(玉米糁、大米)、黑木耳春笋烧鸡、糖醋白菜、绿豆南瓜汤。");
}
@Override
public void study() {
System.out.println("学习打乒乓球");
}
@Override
public void speak() {
System.out.println("讲英语");
}
}
9.测试类
package 运动员和教练;
public class PersonDemo {
public static void main(String[] args) {
TableTennisPlayer p1=new TableTennisPlayer();
p1.setName("彭万里");
p1.setAge("23");
System.out.println(p1.getName()+","+p1.getAge());
p1.eat();
p1.study();
p1.speak();
System.out.println("-----------------------------");
basketballPlayer b1=new basketballPlayer("马宏宇","25");
System.out.println(b1.getName()+","+b1.getAge());
b1.eat();
b1.study();
System.out.println("-----------------------------");
TableTennisCoach p2=new TableTennisCoach("黄强辉","42");
System.out.println(p2.getName()+","+p2.getAge());
p2.eat();
p2.teach();
p2.speak();
System.out.println("-----------------------------");
BasketballCoach b2=new BasketballCoach("程孝先","41");
System.out.println(b2.getName()+","+b2.getAge());
b2.eat();
b2.teach();
System.out.println("-----------------------------");
}
}