例题2-5

来源:互联网 发布:mpu6050单片机电路图 编辑:程序博客网 时间:2024/05/22 05:29


public class Example5 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
    People 张三,李四;
        张三=new People();
        李四=new People();
        Machine 体检器;
                  体检器=new Machine();
                  张三.height=200f;
                  张三.weight=77;
                  张三.speak();
                 体检器.estimate(张三.height,  张三.weight);
                 李四.height=250f;
                 李四.weight=80;
                 李四.speak();
体检器.estimate(李四.height,  李四.weight);
    
 }

}

public class Machine {
 void estimate(float height,int weight){
  double number=(height-100)/weight;
  if(number>=1.1)
   System.out.println("偏瘦");
  else if(number<1.1&&number>=0.96)
   System.out.println("正常");
  else if(number<0.96)
   System.out.println("偏胖");
 }
}

public class People {
 float height;
 int weight;
 void speak(){
  System.out.println("我的身高是"+height+"cm");
  System.out.println("我的体重是"+weight+"kg");
 }

}


原创粉丝点击