標題:
20121015
[打印本頁]
作者:
ray
時間:
2012-10-15 20:10
標題:
20121015
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?"男生":"女生"));
*/
}
}
作者:
ray
時間:
2012-10-15 20:57
import java.util.Scanner;
class Suggestion
{
String suggestion(float mBMI)
{
String mSuggestion = "";
if(mBMI >= 35)
{
mSuggestion = "重度肥胖";
}
else if(mBMI >= 30 && mBMI <35)
{
mSuggestion = "中度肥胖";
}
else if(mBMI >= 27 && mBMI <30)
{
mSuggestion = "輕度肥胖";
}
else if(mBMI >= 24 && mBMI <27)
{
mSuggestion = "過重";
}
else if(mBMI >= 18.5 && mBMI <24)
{
mSuggestion = "標準";
}
else if(mBMI < 18.5)
{
mSuggestion = "過輕";
}
return mSuggestion;
}
}
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();
return (new Suggestion()).suggestion(mBMI);
}
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?"男生":"女生"));
*/
}
}
複製代碼
作者:
吳尚哲
時間:
2012-10-17 01:10
class ManSuggestion
{
String mSuggestion;
String mSuggestion(float mBMI, String mName)
{
if(mBMI >= 35)
{
this.mSuggestion = mName + " 先生" + " 你胖死啦!! BMI: " + mBMI;
}
else if(mBMI >= 30 && mBMI < 35)
{
this.mSuggestion = mName + " 先生" + " 你胖過頭囉! BMI:" + mBMI;
}
else if(mBMI >= 27 && mBMI < 30)
{
this.mSuggestion = mName + " 先生" + " 你太胖囉 ~BMI:" + mBMI;
}
else if(mBMI >= 24 && mBMI < 27)
{
this.mSuggestion = mName + " 先生" + " 你吃太多了唷 BMI:" + mBMI;
}
else if(mBMI >= 18.5 && mBMI < 24)
{
this.mSuggestion = mName + " 先生" + " 真的這麼標準嗎=.= BMI:" + mBMI;
}
else if(mBMI < 18.5)
{
this.mSuggestion = mName + " 先生" + " 你是沒在吃飯嗎?? BMI:" + mBMI;
}
else
{
this.mSuggestion = "你確定??" + mBMI;
}
return mSuggestion;
}
}
class WomanSuggestion
{
String mSuggestion;
String mSuggestion(float mBMI, String mName)
{
if(mBMI >= 35)
{
this.mSuggestion = mName + " 女士" + " 請注意健康! BMI: " + mBMI;
}
else if(mBMI >= 30 && mBMI < 35)
{
this.mSuggestion = mName + " 女士" + " 該控制一下飲食作息囉 ... BMI:" + mBMI;
}
else if(mBMI >= 27 && mBMI < 30)
{
this.mSuggestion = mName + " 女士" + " 瘦一點會更好唷~ BMI:" + mBMI;
}
else if(mBMI >= 24 && mBMI < 27)
{
this.mSuggestion = mName + " 女士" + " 還算標準啦^^ BMI:" + mBMI;
}
else if(mBMI >= 18.5 && mBMI < 24)
{
this.mSuggestion = mName + " 女士" + " 妳十分健康唷^^ BMI:" + mBMI;
}
else if(mBMI < 18.5)
{
this.mSuggestion = mName + " 女士" + " 該多一點飯啦~ BMI:" + mBMI;
}
else
{
this.mSuggestion = "妳確定??" + mBMI;
}
return mSuggestion;
}
}
public class BMIManager
{
String mName;
float mHeight;
float mWeight;
boolean mSex;
float mBMI = 0;
String mSuggestion;
BMIManager(String n, float h, float w, boolean s) //建構子
{
this.mName = n;
this.mHeight = h;
this.mWeight = w;
this.mSex = s;
}
void setName(String n)
{
this.mName = n;
}
void setHeight(float h)
{
this.mHeight = h;
}
void setWeight(float w)
{
this.mHeight = w;
}
void setSex(boolean s)
{
this.mSex = s;
}
float getHeight()
{
return this.mHeight;
}
float getWeight()
{
return this.mWeight;
}
boolean getSex()
{
return this.mSex;
}
float caculateBMI()
{
float h;
h = (this.mHeight/100)*(this.mHeight/100);
this.mBMI = this.mWeight/h;
return this.mBMI;
}
String suggestion()
{
if(mBMI==0)
caculateBMI();
if(mSex)
{
this.mSuggestion = (new ManSuggestion()).mSuggestion(mBMI, mName);
}
else
{
this.mSuggestion = (new WomanSuggestion()).mSuggestion(mBMI, mName);
}
return this.mSuggestion;
}
}
複製代碼
import java.util.Scanner;
public class MyBMI
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String name;
float h;
float w;
boolean s;
System.out.println("請輸入您的大名 : ");
name = 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(name, h, w, s);
myBMI.caculateBMI();
System.out.println(myBMI.suggestion());
}
}
複製代碼
作者:
陳建志
時間:
2012-10-17 14:54
import java.util.Scanner;
class Suggestion
{
String suggestion_man(float mBMI)
{
String mSuggestion = "";
if(mBMI >= 35)
{
mSuggestion = " 先生重度肥胖";
}
else if(mBMI >= 30 && mBMI <35)
{
mSuggestion = " 先生中度肥胖";
}
else if(mBMI >= 27 && mBMI <30)
{
mSuggestion = " 先生輕度肥胖";
}
else if(mBMI >= 24 && mBMI <27)
{
mSuggestion = " 先生過重";
}
else if(mBMI >= 18.5 && mBMI <24)
{
mSuggestion = " 先生標準";
}
else if(mBMI < 18.5)
{
mSuggestion = " 先生過輕";
}
return mSuggestion;
}
String suggestion_woman(float mBMI)
{
String mSuggestion = "";
if(mBMI >= 35)
{
mSuggestion = " 小姐重度肥胖";
}
else if(mBMI >= 30 && mBMI <35)
{
mSuggestion = " 小姐中度肥胖";
}
else if(mBMI >= 27 && mBMI <30)
{
mSuggestion = " 小姐輕度肥胖";
}
else if(mBMI >= 24 && mBMI <27)
{
mSuggestion = " 小姐過重";
}
else if(mBMI >= 18.5 && mBMI <24)
{
mSuggestion = " 小姐標準";
}
else if(mBMI < 18.5)
{
mSuggestion = " 小姐過輕";
}
return mSuggestion;
}
}
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 (mSex == true)
{
return (new Suggestion()).suggestion_man(mBMI);
}
else
{
return (new Suggestion()).suggestion_woman(mBMI);
}
}
/*
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?"男生":"女生"));
}
*/
}
複製代碼
作者:
陳建志
時間:
2012-10-17 14:55
import java.util.Scanner;
public class MyBMI
{
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.print(yourname + myBMI.suggestion());
}
}
複製代碼
回復
4#
陳建志
作者:
晏有聰
時間:
2012-10-17 18:09
import java.util.Scanner;
class ManSuggestion
{
String suggestion(float mBMI)
{
String mSuggestion = "";
if(mBMI >= 35)
{
mSuggestion = "重度肥胖,你是神豬嗎 ?";
}
else if(mBMI >= 30 && mBMI <35)
{
mSuggestion = "中度肥胖,恭喜你可以請人家幫忙綁鞋帶!";
}
else if(mBMI >= 27 && mBMI <30)
{
mSuggestion = "過重,低頭快看不到你的腳趾頭了!";
}
else if(mBMI >= 24 && mBMI <27)
{
mSuggestion = "稍重,恭喜你還可以蹲下去綁鞋帶!";
}
else if(mBMI >= 18.5 && mBMI <24)
{
mSuggestion = "標準,帥哥一枚保持下去!";
}
else if(mBMI < 18.5)
{
mSuggestion = "過輕!!,紙片人!";
}
return mSuggestion;
}
}
class WomanSuggestion
{
String suggestion(float mBMI)
{
String mSuggestion = "";
if(mBMI >= 35)
{
mSuggestion = "不要每年都咬橘子壓!";
}
else if(mBMI >= 30 && mBMI <35)
{
mSuggestion = "太豐腴了 , 擋住我的電視了!";
}
else if(mBMI >= 27 && mBMI <30)
{
mSuggestion = "有點豐腴喔 , 注意一下飲食喔!";
}
else if(mBMI >= 24 && mBMI <27)
{
mSuggestion = "體重有點重,少吃一點會更好喔!";
}
else if(mBMI >= 18.5 && mBMI <24)
{
mSuggestion = "標準喔,正妹一個喔!";
}
else if(mBMI < 18.5)
{
mSuggestion = "過輕,再多吃一點會更好喔!";
}
return mSuggestion;
}
}
public class BMIManager {
private float mHeight;
private float mWeight;
private String mSex;
private float mBMI=0;
String msuggestion;
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(String s)
{
this.mSex=s;
}
String getSex()
{
if (mSex.equals("M"))
mSex="男士";
else if(mSex.equals("F"))
mSex="女士";
else
mSex="無法判別";
return this.mSex;
}
BMIManager(float h , float w , String s)
{
this.mHeight=h;
this.mWeight=w;
this.mSex=s;
}
float calculateBMI()
{
if (mBMI==0)
{
mBMI = (mWeight/((mHeight/100)*(mHeight/100)));
}
return mBMI;
}
String suggestion()
{
if(mBMI == 0)
calculateBMI();
if (mSex.equals("男士"))
return (new ManSuggestion()).suggestion(mBMI);
else
return (new WomanSuggestion()).suggestion(mBMI);
}
}
import java.util.Scanner;
public class BMIManagerTest {
public static void main(String[] args) {
String name,sex;
float hight;
float weight;
Scanner scan = new Scanner(System.in);
System.out.print("請輸入您的姓名=");
name=scan.next();
System.out.print("請輸入你的身高(cm)=");
hight=Float.parseFloat(scan.next());
System.out.print("請輸入你的體重(kg)=");
weight=Float.parseFloat(scan.next());
System.out.print("請輸入你的性別 M or F =");
sex=scan.next();
BMIManager myBMI = new BMIManager (hight , weight , sex);
System.out.println("親愛的 "+name+" "+myBMI.getSex()+" ,您的BMI="+myBMI.calculateBMI());
System.out.println(myBMI.suggestion());
}
}
請輸入您的姓名=kkman
請輸入你的身高(cm)=170
請輸入你的體重(kg)=99
請輸入你的性別 M or F =M
親愛的 kkman 男士 ,您的BMI=34.256054
中度肥胖,恭喜你可以請人家幫忙綁鞋帶!
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2