import java.util.Scanner;
class BMIManager
{
private float mHeight;
private float mWeight;
private boolean mSex;
private float mBMI;
private String mSuggestion;
BMIManager(float h,float w,boolean s)
{
this.mHeight = h;
this.mWeight = w;
this.mSex = s;
this.mBMI = 0;
}
void setHeight(float h)
{
this.mHeight = h;
}
float getHeight()
{
return this.mHeight;
}
void setWeight(float w)
{
this.mWeight = w;
}
float getWeight()
{
return this.mWeight;
}
void setSex(boolean s)
{
this.mSex = s;
}
boolean getSex()
{
return this.mSex;
}
float calculateBMI()
{
if(this.mBMI == 0)
{
float h = this.mHeight/100;
h = h * h;
this.mBMI = this.mWeight/h;
}
return this.mBMI;
}
String suggestion()
{
if(mBMI == 0)
calculateBMI();
if(this.mBMI >= 35)
{
mSuggestion = "重度肥胖";
}
else if(this.mBMI >= 30 && this.mBMI <35)
{
mSuggestion = "中度肥胖";
}
else if(this.mBMI >= 27 && this.mBMI <30)
{
mSuggestion = "輕度肥胖";
}
else if(this.mBMI >= 24 && this.mBMI <27)
{
mSuggestion = "過重";
}
else if(this.mBMI >= 18.5 && this.mBMI <24)
{
mSuggestion = "標準";
}
else if(this.mBMI < 18.5)
{
mSuggestion = "過輕";
}
return mSuggestion;
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String yourname;
float h;
float w;
boolean s;
System.out.println("請輸入您的大名 : ");
yourname = scan.next();
System.out.println("請輸入您的身高 : ");
h = Float.parseFloat(scan.next());
System.out.println("請輸入您的體重 : ");
w = Float.parseFloat(scan.next());
System.out.println("請輸入您是男生(1)/女生(0) :");
s = Integer.parseInt(scan.next())==1;
BMIManager myBMI = new BMIManager(h,w,s);
System.out.print(myBMI.calculateBMI()+"\n");
System.out.printf("%s",myBMI.suggestion());
/*
System.out.println("您輸入的大名 :"+yourname);
System.out.println("您輸入的身高 :"+myBMI.mHeight);
System.out.println("您輸入的體重 :"+myBMI.getWeight());
System.out.println("您輸入您是:"+(myBMI.getSex()==true?"男生":"女生"));
*/
}
} |