namereq

ex23_03

Jun 20th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. // Ex2303_Broca.java
  2. public class Ex2303_Broca{
  3.     private double height;
  4.     public Ex2303_Broca(double height){
  5.         this.height = height;
  6.     }
  7.     public double getHeight(){
  8.         return this.height;
  9.     }
  10.    
  11.     public double getStandardWeight(){
  12.         return (this.height - 100) * 0.9;
  13.     }
  14. }
  15. // Ex2303_BMI.java
  16. public class Ex2303_BMI extends Ex2303_Broca{
  17.     public Ex2303_BMI(double height){
  18.         super(height);
  19.     }
  20.     public double getStandardWeight(){
  21.         return (super.getHeight() / 100) * (super.getHeight() / 100) * 23;
  22.     }
  23. }
  24. // ex23_03.java
  25. import java.util.*;
  26. public class ex23_03{
  27.     public static void main(String[] args){
  28.         double height;
  29.         Scanner sc = new Scanner(System.in);
  30.        
  31.         for(;;){
  32.             System.out.print("身長を入力してください(cm)>");
  33.             height = sc.nextDouble();
  34.             if(height == 0.0) break;
  35.             if(height < 0.0) continue;
  36.             System.out.print("ブローカ標準体重:");
  37.             System.out.println(new Ex2303_Broca(height).getStandardWeight());
  38.             System.out.print("BMI 標準体重:");
  39.             System.out.println(new Ex2303_BMI(height).getStandardWeight());
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment