zoukankan      html  css  js  c++  java
  • 计算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());
    }
    }

    只相信苦尽甘来
  • 相关阅读:
    mono for android学习过程系列教程(6)
    mono for android学习过程系列教程(5)
    mono for android学习过程系列教程(4)
    mono for android学习过程系列教程(3)
    mono for android学习过程系列教程(2)
    mono for android学习过程系列教程(1)
    随笔索引
    中国大学MOOC中的后台文件传输
    知乎控件分享(一)
    知乎UWP 预览
  • 原文地址:https://www.cnblogs.com/F001li/p/7055842.html
Copyright © 2011-2022 走看看