用一个小程序计算BMI

代码如下:

package Day06;

public class BMI {
private String name;
private int age;
private double height;//cm
private double weight;//kg
public static final double KILOGRAMS_PER_POUND = 0.45359237;
public static final double METERS_PER_INCH = 0.0254;

/**
* @param name
* @param age
* @param height
* @param weight
*/
public BMI(String name, int age, double height, double weight) {
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the height
*/
public double getHeight() {
return this.height;
}

public double getHeightInInches() {
return this.height / METERS_PER_INCH / 100;
}
/**
* @param height the height to set
*/
public void setHeight(double height) {
this.height = height;
}
/**
* @return the weight
*/
public double getWeight() {
return this.weight;
}

public double getWeightInPound() {
return this.weight / KILOGRAMS_PER_POUND;
}

/**
* @param weight the weight to set
*/
public void setWeight(double weight) {
this.weight = weight;
}

public double getBMIValue() {
double heightInMeters = this.height / 100;
return this.weight / (heightInMeters * heightInMeters);
}

public static void main(String[] args) {
BMI bmi = new BMI("JOHN", 18, 180, 70);
System.out.println(bmi.getName());
System.out.println(bmi.getAge());
System.out.println(bmi.getBMIValue());
System.out.println(bmi.getWeightInPound());
System.out.println(bmi.getHeightInInches());
}
}

计算BMI的更多相关文章

  1. Python3实现计算BMI指数,跟我一起来计算你的BMI吧

    废话不多说,直接上程序哈: name=input('Name:') height=input('Height(m):') weight=input('Weight(kg):') BMI=float(f ...

  2. 计算BMI指数的小程序

    小明身高1.75,体重80.5kg.请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数: 低于18.5:过轻 18.5-25:正常 25-28:过重 28-32:肥胖 高 ...

  3. 用面向对象计算BMI指数

    from __future__ import division class Student: def __init__(self,name,weight,height): self.name=name ...

  4. 《Python之BMI计算》

    <Python之BMI计算> 前段时间写了个 BMI 因为刚刚开始学 有几个错误 第一个: 厘米我当时也没注意因为觉得去掉0.00的话后面1866666666是正确的BMI值 刚刚去看看去 ...

  5. ----------BMI指数小程序----------

    # 1.创建并输出菜单, 菜单是不可变的. 所以使用元组# menus = ("1, 录入", "2, 查询", "3, 删除", &quo ...

  6. python写BMI指数菜单

    需求: # 1.创建并输出菜单, 菜单是不可变的. 所以使用元组menus = ("1, 录入", "2, 查询", "3, 删除", &q ...

  7. [Architecture Design] 跨平台架构设计

    [Architecture Design] 跨平台架构设计 跨越平台 Productivity Future Vision 2011 在开始谈跨平台架构设计之前,请大家先看看上面这段影片,影片内容是微 ...

  8. Angular 2.0 从0到1:Rx--隐藏在Angular 2.x中利剑

    第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2.0 从0到1 (三)第四节:Angular 2.0 从0到1 (四)第五节: ...

  9. Haskell函数的语法

    本章讲的就是 Haskell 那套独特的语法结构,先从模式匹配开始.模式匹配通过检查数据的特定结构来检查其是否匹配,并按模式从中取得数据. 在定义函数时,你可以为不同的模式分别定义函数本身,这就让代码 ...

随机推荐

  1. [HDU1020] Encoding - 加密

    Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...

  2. [HDU1004] Let the balloon rise - 让气球升起来

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  3. 用pickle模块实现“增删改查”的简易功能

    pickle的作用: 1:pickle.dump(dict,file)把字典转为二进制存入文件. 2:pickle.load(file)把文件二进制内容转为字典 import pickle # 增 d ...

  4. Promise实现多图预加载

    Promise正如它的中文意思“承诺”一样,保存着未来会发生事件(一般为异步操作).Promise避免了“回调地狱”,写法更加接近同步操作.说到同步,我更加喜欢async.await,它们书写更贴近同 ...

  5. Codility---MaxProfit

    Task description A zero-indexed array A consisting of N integers is given. It contains daily prices ...

  6. [0] 关于IComparable和IComparer接口和Comparer类

    关于IComparable和IComparer接口 和 Comparer类 IComparable和ICompareframeworkr接口是.net 中比较对象的标准方式,这两个接口之间的区别如下: ...

  7. Wowza 部署 安装 配置 测试 直播

    下载,最好用快的IP下好后传到需要的节点上,下面链接不能下载的情况下百度谷歌必应找资源,jdk旧版在oracle需登录方可下载 JDK1.6 wget -c http://dl.download.cs ...

  8. linux系统最常用命令(持续更新)

    1.重启服务器 ubuntu系统重启apache:/etc/init.d/apache2 restart linux重启nginx: service nginx restart 重新加载:servic ...

  9. javaScript操作DOM对象(看三遍,敲三遍,写三遍! 不会你找我)!!

    DOM是Document Object Model的缩写,即文档对象模型,是基于文档编程的一套API 使用javaScript操作DOM对象通常分为三类:1.DOM CORE        2.HTM ...

  10. document事件及例子

    一.关于鼠标事件:onclick:鼠标单击触发 ondbclick:鼠标双击触发 onmouseover:鼠标移上触发 onmouseout:鼠标离开触发 onmousemove:鼠标移动触发 二.关 ...