Re: 人的特色只有好人與坏人嗎?

看板java作者 (好像冷氣吹太多了)時間19年前 (2006/08/30 22:03), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/2 (看更多)
※ 引述《www@bbs.ee.ntu.edu.tw (web)》之銘言: : 人的特色只有好人與坏人嗎? 這麼富有哲學性的問題,既然在Java板出現了,就一定要認真地用Java的方式來回答。 話說,人類是萬物之靈,所以人類也是物件的一種。然而要具體形容一個人,除了外觀, 當然還有道德、職業、學經歷、聲望這些因素等等…這些要素,在還沒有能夠具體形容這 些要素前,我們能做的,就是暫時將人化做一個簡陋的抽象類別。 package universe.earth; public abstract class Human { protected boolean isNormal; protected boolean isGoodGuy; protected String sex; protected double weight; protected double height; protected double BMI; public Human(){} public abstract boolean IsNormal(boolean eyebrow); public abstract boolean IsGoodGuy(String skill); public abstract void setBMI(double weight, double height); } 基本上,人類又可分為帶把與沒帶把的!皆下來我們就要實做這個帶把的男人類別,他繼 承自Human這個抽象類別。 package universe.earth; public class Male extends Human{ // Of course, this a male class public Male(){ sex = "male"; this.isNormal = true; this.isGoodGuy = false; // 人心險惡,先認為不是好人吧! } // Is his look normal? public boolean IsNormal(boolean eyebrow){ if(eyebrow){ this.isNormal = true; }else{ this.isNormal = false; } return isNormal; } // Is he a good guy? public boolean IsGoodGuy(String skill){ if(skill == null || skill.equalsIgnoreCase("java")){ this.isGoodGuy = true; }else{ this.isGoodGuy = false; // Are you a C# user?; } return isGoodGuy; } // Check his body is strong, weak, or normal. public void setBMI(double weight, double height){ this.weight = weight; this.height = height; BMI = 10000*weight/Math.pow(height, 2); } // overridden toString() public String toString(){ String description = "He is a " + sex +".\n"; if(isNormal && isGoodGuy && BMI >0){ description += "Good! You should make friend with him."; }else if(!isNormal && isGoodGuy && BMI >0){ description += "He might be a good friend, but don't laught at his eyebow."; }else if(!isNormal && !isGoodGuy && BMI >0){ description += "Please, he's just with no eyebrow!"; }else if(BMI < 18.5 && BMI > 0){ description += "You might win at this fight!"; }else if(BMI > 24.9){ description += "Run! Frost! Run!"; }else { description += "It's a even fight!"; } return description+"\n"; } } 好!我們做到這,我們可以基於一個人有沒有眉毛、專長、以及BMI決定這個人好不好相 處。所以我們開始將這個male類別實例化。 package universe.earth; public class JudgeHuman { public final static void main(String[] args){ Male thisGuy = new Male(); // 路上兩人相見,不熟悉! System.out.println("You haven't analyze who he is..."); System.out.println(thisGuy.toString()); // 然後你推測他的身高體重,算出他的BMI... thisGuy.setBMI(100,183); System.out.println("After you know his BMI..."); System.out.println(thisGuy.toString()); // 然後你又看了一下他的臉,發現他沒有眉毛! thisGuy.IsNormal(false); System.out.println("After you analyze his face..."); System.out.println(thisGuy.toString()); // 最後他告訴你,他原來是個java程式設計師! thisGuy.IsGoodGuy("java"); System.out.println("After you know his skills..."); System.out.println(thisGuy.toString()); } } 將這個Java application執行後的結果如下: You haven't analyze who he is... He is a male. It's a even fight! After you know his BMI... He is a male. Run! Frost! Run! After you analyze his face... He is a male. Please, he's just with no eyebrow! After you know his skills... He is a male. He might be a good friend, but don't laught at his eyebow. 所以,結論就是... 人的特色當然不是只有好人或壞人囉! (好吧!我承認我來騙稿費的...) -- No Dying Skills, ● - Dame! New tech... but Lazy Users. .\) http://www.wretch.cc/blog/hougzou ___________ ﹒ ︵ √\ ___________________ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.104.1.128

08/30 22:16, , 1F
雖然看得很囧... 不過還是賞你一個 m
08/30 22:16, 1F
文章代碼(AID): #14zPgaBz (java)
文章代碼(AID): #14zPgaBz (java)