/**
乒乓球运动员和教练
篮球运动员和教练
为了出国交流,乒乓球运动员和教练需要说英语。
请你用所学知识,分析,这里应该有哪些类,抽象类,接口
*/
//接口
interface SpeakEnglish
{
public abstract void speak();
}
abstract class Person
{
private String name;
private int age;
public Person(){}
public Person(String name,int age){
this.name=name;
this.age=age;
}
public void setName(String name){
this.name=name;
}
public String name(){
return name;
}
public void setAge(int age){
this.age=age;
}
public int age(){
return age;
}
public void sleep()
{
System.out.println("睡觉");
}
public void show(){
System.out.println(name+"----"+age);
}
//吃饭的方法
public abstract void eat();
}
abstract class Player extends Person
{
public Player(){}
//学习的方法
public abstract void study();
}
abstract class Coach extends Person
{
public Coach(){}
//教的方法
public abstract void teach();
}
class PingPangPlayer extends Player implements SpeakEnglish
{
public PingPangPlayer(){}
public void speak(){
System.out.println("乒乓球运动员学习英语");
}
public void eat(){
System.out.println("乒乓球运动员吃营养餐");
}
public void study(){
System.out.println("乒乓球运动员学习接发球");
}
}
class PingPangCoach extends Coach implements SpeakEnglish
{
public PingPangCoach(){}
public void speak(){
System.out.println("乒乓球教练学习英语");
}
public void eat(){
System.out.println("乒乓球教练吃白米饭");
}
public void teach(){
System.out.println("乒乓球教练教如何接发球");
}
}
class Basketplayer extends Player
{
public Basketplayer(){}
public void eat(){
System.out.println("篮球运动员吃牛肉面");
}
public void study(){
System.out.println("运动员球员学习运球,投篮");
}
}
class BasketCoach extends Coach
{
public BasketCoach(){}
public void eat(){
System.out.println("篮球运动员喝牛肉汤");
}
public void teach(){
System.out.println("运动员球员教运球,投篮");
}
}
class PersonTest
{
public static void main(String[] args)
{
//乒乓球运动员
PingPangPlayer p = new PingPangPlayer();
p.setName("邓亚萍");
p.setAge(50);
p.show();
p.speak();
p.eat();
p.study();
//篮球运动员
Basketplayer b = new Basketplayer();
b.setName("姚明");
b.setAge(30);
b.show();
b.eat();
b.study();
//乒乓球教练
PingPangCoach pp = new PingPangCoach();
pp.setName("李宁");
pp.setAge(60);
pp.show();
pp.speak();
pp.eat();
pp.teach();
//篮球教练
BasketCoach bb = new BasketCoach();
bb.setName("乔丹");
bb.setAge(50);
bb.show();
bb.eat();
bb.teach();
}
}
|
|