Java 创建三个类People、ChinaPeople、AmericanPeople,其中People是父类,另外两个是其子类

题目:

【问题描述】
创建三个类People、ChinaPeople、AmericanPeople,其中People是父类,另外两个是其子类。父类和测试类已经有完整定义了,根据输出结果,完成ChinaPeople和AmericanPeople的编写。

【输入形式】

【输出形式】
相应字符串。

【样例输入】

【样例输出】
hello,I am ChinaPeople.
avarge heigh of ChinaPeople:180.0
average weight of ChinaPeople:130.0
I can gongfu.
hello,I am American!
avarge heigh of American:175.0
average weight of American:150.0
I can boxing.

代码:

class  People  {
    protected  double  height;
    protected  double  weight;

    public  double  getHeight()  {
            return  height;
    }

    public  void  setHeight(double  height)  {
            this.height  =  height;
    }

    public  double  getWeight()  {
            return  weight;
    }

    public  void  setWeight(double  weight)  {
            this.weight  =  weight;
    }

    public  void  speakHello()  {
            System.out.println("hello!");
    }

    public  void  averageHeight()  {
            System.out.println("avarge  heigh:"  +  height);
    }

    public  void  averageWeight()  {
            System.out.println("average  weight:"  +  weight);
    }
}
class  AmericanPeople  extends  People  {
    public void speakHello() {
    	System.out.println("hello,I am American!");
    }
    public  void  averageHeight()  {
        System.out.println("avarge heigh of American:"  +  height);
}
    public  void  averageWeight()  {
        System.out.println("average weight of American:"  +  weight);
}
	public void amercianBoxing() {
		System.out.println("I can boxing.");
	} 
	
}
class  ChinaPeople  extends  People  {
	 public void speakHello() {
	    	System.out.println("hello,I am ChinaPeople.");
	    }
	 public  void  averageHeight()  {
         System.out.println("avarge heigh of ChinaPeople:"  +  height);
 }
	 public  void  averageWeight()  {
         System.out.println("average weight of ChinaPeople:"  +  weight);
 }
	public void chinaGongfu() {
		System.out.println("I can gongfu.");
	} 
	
}
public  class  TestPeople  {
        public  static  void  main(String[]  args)  {
                ChinaPeople  chp  =  new  ChinaPeople();
                chp.height  =  180;
                chp.weight  =  130;
                chp.speakHello();
                chp.averageHeight();
                chp.averageWeight();
                chp.chinaGongfu();
                AmericanPeople  amp  =  new  AmericanPeople();
                amp.setHeight(175);
                amp.setWeight(150);
                amp.speakHello();
                amp.averageHeight();
                amp.averageWeight();
                amp.amercianBoxing();
        }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱犯错的小z

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值