计算BMI
用一个小程序计算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的更多相关文章
- Python3实现计算BMI指数,跟我一起来计算你的BMI吧
废话不多说,直接上程序哈: name=input('Name:') height=input('Height(m):') weight=input('Weight(kg):') BMI=float(f ...
- 计算BMI指数的小程序
小明身高1.75,体重80.5kg.请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数: 低于18.5:过轻 18.5-25:正常 25-28:过重 28-32:肥胖 高 ...
- 用面向对象计算BMI指数
from __future__ import division class Student: def __init__(self,name,weight,height): self.name=name ...
- 《Python之BMI计算》
<Python之BMI计算> 前段时间写了个 BMI 因为刚刚开始学 有几个错误 第一个: 厘米我当时也没注意因为觉得去掉0.00的话后面1866666666是正确的BMI值 刚刚去看看去 ...
- ----------BMI指数小程序----------
# 1.创建并输出菜单, 菜单是不可变的. 所以使用元组# menus = ("1, 录入", "2, 查询", "3, 删除", &quo ...
- python写BMI指数菜单
需求: # 1.创建并输出菜单, 菜单是不可变的. 所以使用元组menus = ("1, 录入", "2, 查询", "3, 删除", &q ...
- [Architecture Design] 跨平台架构设计
[Architecture Design] 跨平台架构设计 跨越平台 Productivity Future Vision 2011 在开始谈跨平台架构设计之前,请大家先看看上面这段影片,影片内容是微 ...
- 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 (四)第五节: ...
- Haskell函数的语法
本章讲的就是 Haskell 那套独特的语法结构,先从模式匹配开始.模式匹配通过检查数据的特定结构来检查其是否匹配,并按模式从中取得数据. 在定义函数时,你可以为不同的模式分别定义函数本身,这就让代码 ...
随机推荐
- PHP数组简介
一.PHP数组的分类 按照下标的不同,PHP中的数组分为关联数组和索引数组:索引数组:下标从0开始,依次增长. $arr=[1,2,3,4,5]; 关联数组:下标为字符串格式,每个下标字符串与数组的值 ...
- UVALive-5731
UVALive-5731 题意 一颗 n - 1 条边的有向树,要求整棵树成为强连通图,一次操作即构建一条路(一笔画), 限制: 新建的路上的所有边必须与原有的边逆向,即构建的路必须在原有的边和点上, ...
- react 基础
一.组件 函数式定义的无状态组件 es5原生方式React.createClass定义的组件 es6形式的extends React.Component定义的组件 React.Component是以E ...
- python 标准库 -- re
re 正则表达式 语法 import re m = re.search('[0-9]','abc4def67') # 匹配字符及匹配范围 print m.group(0) # 返回匹配结果 re.se ...
- wildfly10报错2:ID注释有错
13:55:56,612 INFO [org.jboss.modules] (main) JBoss Modules version 1.5.1.Final 13:55:56,891 INFO [or ...
- C#继承的执行顺序
自己对多态中构造函数.函数重载执行顺序和过程一直有些不理解,经过测试,对其中的运行顺序有了一定的了解,希望对初学者有些帮助. eg1: public class A { public A() { Co ...
- Ubuntu命令模式基础
Ubuntu是一个自由.开源.基于Debian的Linux发行版.在ubuntu的基础上,又衍生其它各具特色的Linux发行版.首先是一个操作系统,操作系统用于管理电脑硬件.要发挥出电脑的作用,还得依 ...
- json转javascript对象
json转javascript对象var tpIdObj = eval("(" + tpid + ")");//json字符串转 对象var tpid = JS ...
- --css 控制文字多使用省略号
--css 控制文字多使用省略号.overflowPoint{ text-overflow:ellipsis;width: 200px;overflow: hidden;}<div class= ...
- Angular4 后台管理系统搭建(2) - flexgrid 单元格模板 wjFlexGridCellTemplate 的坑
这几天中了很多坑,尤其是两个大坑.先是运行环境的坑,在是flexgrid单元格内部模板的坑.这里记录下. 一开始我遇见一些很奇怪的问题,按网上的说法,别人这么写代码都正常,就在我机器上不正常.按以前的 ...