日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Java黑皮书课后题第10章:10.2(BMI类)将下面的新构造方法加入BMI类中

發(fā)布時(shí)間:2024/8/1 java 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java黑皮书课后题第10章:10.2(BMI类)将下面的新构造方法加入BMI类中 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Java黑皮書課后題第10章:10.2(BMI類)將下面的新構(gòu)造方法加入BMI類中

  • 題目
    • 程序說明
    • 題目槽點(diǎn)
  • 代碼:Test2_BMI.java
  • 運(yùn)行實(shí)例

題目

程序說明

Test2_BMI.java:BMI類程序
這里我們參考編程練習(xí)題3.6的代碼

題目槽點(diǎn)

題目內(nèi)容表述的非常簡略,簡略得已經(jīng)有很多地方省略了
剛開始根本搞不清楚出題人到底想干什么
后來才逐漸意識到應(yīng)該把給出的構(gòu)造方法和測試程序放在一起
我個(gè)人想到在前面本來也有求BMI的題,所以用到3.6的內(nèi)容

代碼:Test2_BMI.java

import java.util.Scanner;public class Test2_BMI {double weight, height_feet, height_inches;String name;int age;private static double KILOGRAMS_PER_POUND = 0.45359237;private static double METERS_PER_FEET = 0.3048;private static double METERS_PER_INCH = 0.0254;public Test2_BMI(String name, int age, double weight, double feet, double inches){this.age = age;this.name = name;this.weight = weight;height_feet = feet;height_inches = inches;}public double getBMI(){// Compute BMIdouble weightInKilograms = weight * KILOGRAMS_PER_POUND;double heightInMeters = height_feet * METERS_PER_FEET + height_inches * METERS_PER_INCH;return weightInKilograms / (Math.pow(heightInMeters,2));}public static void main(String[] args){Scanner input = new Scanner(System.in);// Prompt the user to enter weight in poundsSystem.out.print("Enter weight in pounds: ");double weight = input.nextDouble();// Prompt the user to enter height in feetSystem.out.print("Enter feet: ");double height_feet = input.nextDouble();// Prompt the user to enter height in inchesSystem.out.print("Enter inches: ");double height_inches = input.nextDouble();System.out.print("Enter name: ");String name = input.next();System.out.print("Enter age: ");int age = input.nextInt();Test2_BMI tb = new Test2_BMI(name, age, weight, height_feet, height_inches);double bmi = tb.getBMI();// Display resultSystem.out.println("BMI is "+bmi);if(bmi < 18.5)System.out.println("Underweight");else if(bmi < 25)System.out.println("Normal");else if(bmi < 30)System.out.println("Overweight");elseSystem.out.println("Obese");} }

運(yùn)行實(shí)例

Enter weight in pounds: 140 Enter feet: 5 Enter inches: 10 Enter name: liming Enter age: 20 BMI is 20.087702275404553 Normal

總結(jié)

以上是生活随笔為你收集整理的Java黑皮书课后题第10章:10.2(BMI类)将下面的新构造方法加入BMI类中的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。