※ 引述《Contactman.bbs@bbs.badcow.com.tw (上B只為剿小白出氣!)》之銘言:
: 你不是想學物件導向的程式嗎?
: 我就寫個範例讓你了解一下.
這時候就知道寫虛擬碼跟定義變數名稱的重要性了....
: Class BBSguy
: {
: mnIQ = 100; //For normal human
: mnEQ = 100; //For normal human
: public void Post(Article oQuestion) {
: if (oQuestion.CanBeGoogle()) {
: mnIQ = mnIQ - 10;
: }
: if (oQuestion.IsChallenge()) {
: mnEQ = mnEQ - 10;
: }
: }
: public bool IsSmartGuy() {
: return (mnIQ > 50);
: }
: public bool HasBeenMistake() {
: return !(IsSmartGuy);
: }
: public static Article MakeChallenge() {
: return Article.MakeAngryGarbage();
: }
: }
: ---------------------------------------------------
: BBSguy andygogo = new BBSguy();
: Article oQuestion = Google.GetFAQ();
: while(andygogo.IsSmartGuy())
: {
: andygogo.Post(oQuestion);
: if (oQuestion.GetResponseCount < 1)
: {
: andygogo.Post(BBSguy.MakeChallenge());
: }
: }
: System.out.printf(" Is Andygogo a smart boy? " +
: (Andygogo.IsSmartGuy()) ? "Yes!" : "No!");
: 這就是用物件導向的方式描述你正在做的事情.
: 研究一下程式跑完輸出值是什麼吧....別說我沒有教你.
: (嘿, 沒想到我還真閒~~)
你HasBeenMistake沒有用到喔....
加一點料
==============
BBSguy andygogo = new BBSguy();
StartPost:
Article oQuestion = Google.GetFAQ();
NewPost:
andygogo.Post(oQuestion)
oQuestion.FirstResponse
while (oQuestion.AtLastResponse) {
switch oQuestion.ResponseType
case CENSURE:
andygogo.AddCensureList(oQuestion.ResponseBBSguy);
case RTFM:
andygogo.Post(BBSguy.MakeChallenge());
break;
case GUIDANCE:
andygogo.Post(BBSguy.MakeIgnore())
}
oQuestion.NextResponse
}
if(andygogo.IsSmartGuy()) goto StartPost;
if(andygogo.CensureList > 0) {
oQuestion = andygogo.MakeCensure()
goto NewPost;
}
===========
太久沒寫C了,switch跟goto的用法不太確定...
這樣寫class得新增幾個東西才行
--
〒作者:SmallBee 來自:66-207.dorm.ncu.edu.tw
◎二進位的世界【140.115.50.50‧binary.csie.ncu.edu.tw】