Java语言程序设计与数据结构(基础篇)课后练习题 第十章(一

public void setTime(long elapseTime) {

long seconds = elapseTime / 1000;

second = (int) seconds % 60;

seconds /= 60;

minute = (int) seconds % 60;

seconds /= 60;

hour = (int) seconds % 24;

}

}

10.2

=================================================================

前面课文有提及,添加一个方法就行。

public class BMI {

private String name;

private int age;

private double weight;

private double height;

public static final double KILOGRAMS_PER_POUND = 0.45359237;

public static final double METERS_PER_INCH = 0.0254;

public BMI(String name,int age,double weight,double height){

this.name = name;

this.weight = weight;

this.height = height;

this.age = age;

}

public BMI(String name,double weight,double height){

this(name,20,weight,height);

}

public double getBMI(){

double bmi = weight * KILOGRAMS_PER_POUND / ((height * METERS_PER_INCH) * (height * METERS_PER_INCH));

return Math.round(bmi * 100) / 100.0;

}

public String getStatus(){

double bmi = getBMI();

if (bmi < 18.5)

return “Underweight”;

else if (bmi < 25)

return “Normal”;

else if (bmi < 30)

return “Overweight”;

else

return “Obese”;

}

public String getName(){

return name;

}

public int getAge(){

return age;

}

public double getWeight(){

return weight;

}

public double getHeight() {

return height;

}

public BMI(String name,int age,double weight,double feet,double inches){

this.name = name;

this.age = age;

this.weight = weight;

this.height = feet * 12 + inches;

}

}

10.3

===================================================&#

  • 7
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值