Java教练和运动员,乒乓球和篮球出国打比赛,需要学英语

Java教练和运动员,乒乓球和篮球出国打比赛,需要学英语,第1张

Java教练运动员乒乓球和篮球出国打比赛,需要学英语 乒乓球运动员和篮球运动员,乒乓球教练和篮球教练。为了出国交流,跟乒乓球相关的人员都需要学习英语。

先创建一个包,在包中创建如下:

1.抽象类

Person抽象类

package jiekouchouxiang;

public abstract class Person {
    private String name;
    private int age;
    public Person(){

    }
    public Person(String name,int age){
        this.name=name;
        this.age=age;

    }
    public abstract void eat();
    public  void sleep(){
        System.out.println("睡觉要有足够的睡眠");
    }
    public void show(){
        System.out.println("姓名:"+name);
        System.out.println("年龄:"+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;
    }


}

Player抽象类

package jiekouchouxiang;

public abstract class Player extends Person {
    public Player(){
        super();
    }
    public Player(String name,int age){
        super();
    }
    public  abstract  void student();


}

Coach抽象类

package jiekouchouxiang;

public  abstract class Coach extends Person{
    public Coach(){
        super();
    }
    public Coach(String name,int age){
        super();
    }
    public abstract void teacher();
}

2.接口

English接口

package jiekouchouxiang;

public interface English {
    void speak();
}
3.具体类

PingpangPlayer

package jiekouchouxiang;

public  class PingpangPlayer extends Player implements English {
    @Override
    public void student(){
        System.out.println("乒乓球运动员要学习发球和接球技巧");

    }
    @Override
    public  void eat(){
        System.out.println("乒乓球运动员要吃清淡的饭菜");
    }
    @Override
    public void speak(){
        System.out.println("乒乓球运动员要学习英语");
    }

}

PingpangCoach

package jiekouchouxiang;

public  class PingpangCoach extends Coach implements English {
    @Override
    public void teacher(){
        System.out.println("乒乓球教练要教队员发球和接球技巧");

    }
    @Override
    public  void eat(){
        System.out.println("乒乓球教练要吃清淡的饭菜");
    }
    @Override
    public void speak(){
        System.out.println("乒乓球教练要学习英语");
    }
}

BasketballPlayer

package jiekouchouxiang;

public  class BasketballPlayer extends Player {
    @Override
    public void student(){
        System.out.println("篮球运动员要学习运球和投篮技巧");

    }
    @Override
    public  void eat(){
        System.out.println("篮球运动员要吃高蛋白的饭菜");
    }

}

BasketballCoach

package jiekouchouxiang;

public  class BasketballCoach extends Coach {
    @Override
    public void teacher(){
        System.out.println("篮球教练要教队员运球和投篮技巧");

    }
    @Override
    public  void eat(){
        System.out.println("篮球教练要吃高蛋白的饭菜");
    }
}

jiekouchouxiang

package jiekouchouxiang;

public class jiekouchouxiang {
    public static void main(String[] args) {
        PingpangPlayer ppp=new PingpangPlayer();
        ppp.setName("马龙");
        ppp.setAge(18);
        ppp.show();
        ppp.eat();
        ppp.student();
        ppp.speak();
        System.out.println("*********************");
        PingpangCoach ppc=new PingpangCoach();
        ppc.setName("邓亚萍");
        ppc.setAge(38);
        ppc.show();
        ppc.eat();
        ppc.teacher();
        ppc.speak();
        System.out.println("*********************");
        BasketballPlayer bp=new BasketballPlayer();
        bp.setName("易建联");
        bp.setAge(24);
        bp.show();
        bp.eat();
        bp.student();
        System.out.println("*********************");
        BasketballCoach bc=new BasketballCoach();
        bc.setName("姚明");
        bc.setAge(35);
        bc.show();
        bc.eat();
        bc.teacher();
        System.out.println("*********************");

    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5482393.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存