作者hougzou (好像冷气吹太多了)
看板java
标题Re: 人的特色只有好人与坏人吗?
时间Wed Aug 30 22:07:47 2006
※ 引述《[email protected] (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
1F:推 PsMonkey:虽然看得很囧... 不过还是赏你一个 m 08/30 22:16