人类包括中国人和美国人,
中国人包括北京人,
定义类中国人的实际属性有(编号、身高、体重),类属性有(平均身高、平均体重)
最后要显示平均值
定义类美国人可以复制类中国人
建立3个北京人对象和2个中国人对象以上是程序的要求,请大家帮帮忙,解决这个程序问题!谢谢!

解决方案 »

  1.   

    public class Test {
    public static void main(String[] args) {
    BeiJing b1 = new BeiJing(170.0, 55.0);
    BeiJing b2 = new BeiJing(180.0, 65.0);
    BeiJing b3 = new BeiJing(190.0, 75.0); Chinese c1 = new Chinese(175.0, 55.5);
    Chinese c2 = new Chinese(185.0, 65.5); BeiJing.getAverageHeight();
    BeiJing.getAverageWeight(); Chinese.getAverageHeight();
    Chinese.getAverageWeight(); }
    }abstract class Human {
    protected int id; protected double height; protected double weight;}class Chinese extends Human { private static int i = 0; private static int hightSum = 0; private static int weightSum = 0; public Chinese(double height, double weight) {
    hightSum += height;
    weightSum += weight;
    i++;
    } public static double getAverageHeight() {
    double hightAver = hightSum / i;
    System.out.println(hightAver);
    return hightAver;
    } public static double getAverageWeight() {
    double weightAver = weightSum / i;
    System.out.println(weightAver);
    return weightAver;
    }}class American extends Human {
    public American() {
    System.out.println("American");
    } // copy ctor
    public American(Chinese c) {
    this.id = c.id;
    this.height = c.height;
    this.weight = c.weight;
    }
    }class BeiJing extends Chinese { public BeiJing(double height, double weight) {
    super(height, weight);
    hightSum += height;
    weightSum += weight;
    i++;
    } private static int i = 0; private static int hightSum = 0; private static int weightSum = 0; public static double getAverageHeight() {
    double hightAver = hightSum / i;
    System.out.println(hightAver);
    return hightAver;
    } public static double getAverageWeight() {
    double weightAver = weightSum / i;
    System.out.println(weightAver);
    return weightAver;
    }}
      

  2.   

    请大家评价一下我这个!!
    class People
    {
      int code;
      double height,weight;
      
    }
    class Chinese extends People
    {
      static double ave_height=0,ave_weight=0;
      static int count=0;
      Chinese()
      {
      }
      Chinese(int a,double h,double w)
      {
          code=a;
          height=h;
          weight=w;
          count++;
           ave_height=(ave_height*(count-1)+height)/count;
          ave_weight=(ave_weight*(count-1)+weight)/count;
      }  void show()
      {
          
         
          
          System.out.println("中国人的平均身高和平均体重分别为:");
            System.out.println(+ave_height);
            System.out.println(+ave_weight);
            System.out.println("有中国人:"+count);
      }
      }
    class BeiJingren extends Chinese
    {
        
      BeiJingren(int code,double height,double weight)
      {
         
         count++;
          ave_height=(ave_height*(count-1)+height)/count;
          ave_weight=(ave_weight*(count-1)+weight)/count;
      }
      void show()
      {
          
         
          
          System.out.println("北京人的平均身高和平均体重分别为:");
            System.out.println(+ave_height);
            System.out.println(+ave_weight);
             System.out.println("有北京人:"+count);
      }
    }
    class  American extends People
    {  
       static double ave_height1=0,ave_weight1=0;
       static int count1=0;
      American(int a,double h,double w)
      {
          code=a;
          height=h;
          weight=w;
          count1++;
           ave_height1=(ave_height1*(count1-1)+height)/count1;
     
          ave_weight1=(ave_weight1*(count1-1)+weight)/count1;
      }
      void s()
      {
          
         
          
          System.out.println("美国人的平均身高和平均体重分别为:");
           System.out.println(+ave_height1);
           System.out.println(+ave_weight1);
            System.out.println("total of American:"+count1);
      }
    }
    public class Example3
    {
        public static void main(String args[])
        {
            BeiJingren b=new BeiJingren(3,175.5,78);
             BeiJingren b1=new BeiJingren(4,168.7,65);
             BeiJingren b2=new BeiJingren(5,173.0,75);
            b2.show();
            Chinese c=new Chinese(1,170.0,76);
            Chinese c1=new Chinese(2,167.0,65);
            c1.show();
            
            American a=new American(6,178.0,80);
            American a1=new American(7,183.0,86); 
            a1.s();
        }
    }
      

  3.   

    个有个的好处,但我觉得nirvana_li(东成西就,芝兰境界) 做的很细.起码他用了propect来规定.
    还有我觉得,用不用static 声明变量没啥..
      

  4.   

    奶奶的  这个貌似我们JAVA实验三的原题
    实验三:类、对象和继承的应用
    Experiment 3: The Application of Class, Object, Inheritance编写一个java 程序,除了主类外,该程序还有4个类:People, ChinaPeople, AmericaPeople, BeijingPeople类。要求如下:
    (1)People 类有访问权限是 protected 的 double 类型成员变量 height 和 weight,以及 public void speakHello( )、public void averageHeight( ) 和 public void averageWeight( ) 方法。
    (2)ChinaPeople 类是 People 类的子类,新增了 public void chineseGongFu( )方法。要求ChinaPeople 类重写父类的public void speakHello( )、public void averageHeight( ) 和 public void averageWeight( ) 方法。
    (3)AmericaPeople类是 People 类的子类,新增了 public void americanBoxing( )方法。要求AmericaPeople 类重写父类的public void speakHello( )、public void averageHeight( ) 和 public void averageWeight( ) 方法。
    (4)BeijingPeople类是 ChinaPeople 类的子类, 新增了 public void beijingOpera( )方法。要求BeijingPeople 类重写父类的public void speakHello( )、public void averageHeight( ) 和 public void averageWeight( ) 方法。你哪个学校的....