PCDVD數位科技討論區
PCDVD數位科技討論區   註冊 常見問題 標記討論區為已讀

回到   PCDVD數位科技討論區 > 其他群組 > 七嘴八舌異言堂
帳戶
密碼
 

  回應
 
主題工具
risc_bar
Power Member
 
risc_bar的大頭照
 

加入日期: May 2004
文章: 685
DEUCE, THREE, FOUR, FIVE, SIX,
SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE 這些是String 還是你自己定義的class
     
      
舊 2006-09-28, 08:59 AM #11
回應時引用此文章
risc_bar離線中  
doberman
*停權中*
 

加入日期: Mar 2004
文章: 477
定義了Suit, Rank這些variable type,後面method裡也是得回傳object裡的這些variable type.

改完試試看不知有沒好?

/*------------------------------------------
public Card(Suit suit, Rank rank, int value)
{
this.suit = suit;
this.rank = rank;
this.value = value;
}

/**
* Get the suit of the card
* @return String
*/
public Suit getSuit()
{
return this.suit;
}

/**
* Get the rank of the card
* @return String
*/
public Rank getRank()
{
return this.rank;
}

/**
* Get the actual value of the card
* @return int
*/
public int getValue()
{
return this.value;
}



}
-----------------------------*/
 

此文章於 2006-09-28 09:08 AM 被 doberman 編輯.
舊 2006-09-28, 09:05 AM #12
回應時引用此文章
doberman離線中  
gary0718
Major Member
 

加入日期: Aug 2001
您的住址: 新竹
文章: 105
舊 2006-09-28, 09:17 AM #13
回應時引用此文章
gary0718離線中  
青年阿要立死志
New Member
 

加入日期: Sep 2006
文章: 9
private Rank rank;
private Suit suit;
private int value;

這三行就怪怪的
enum類別有final特性
你這樣定義..?

再來
compile error是:

Card.java:39: incompatible types
found : java.lang.String
required: Card.Suit
this.suit = suit;
^
Card.java:40: incompatible types
found : java.lang.String
required: Card.Rank
this.rank = rank;
^
Card.java:50: incompatible types
found : Card.Suit
required: java.lang.String
return this.suit;
^
Card.java:59: incompatible types
found : Card.Rank
required: java.lang.String
return this.rank;
^
4 errors


你的getSuit,getRank
return type是String
getValue是 int

而enum的值根據書本
不可是int或String

可能可以用valueOf()來取得和名稱相同的值
如Rank.valueOf("DEUCE")

不保證對喔
舊 2006-09-28, 09:23 AM #14
回應時引用此文章
青年阿要立死志離線中  
Xforce
Senior Member
 
Xforce的大頭照
 

加入日期: Feb 2002
您的住址: 宜蘭
文章: 1,341
public class Card {

public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX,
SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }

public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
private Rank rank; // the suit of a card
private Suit suit; // the rank of a card
private int value; // the actual value of a card

/**
* Class constructor
* The default Card constructor, creates a new Card object with default values.
*/
public Card()
{
suit = null;
rank = null;
value = 0;
}

/**
* Class constuctor
* Takes the suit, rank and value the card and create a Card object.
* The suit argument must be in either spade, heart, diamond or club. The
* value of rank argument must be chosen from Ace to K. The value argument must
* be an integer from 1 to 13.
* <p>
* One Card object will be created with the given parameters.
*
* @param suit the suit of the card
* @param rank the rank of the card
* @param value the value of the card
*/
public Card(String suit, String rank, int value)
{
this.suit = Suit.valueOf(suit);
this.rank = Rank.valueOf(rank);
this.value = value;
}

/**
* Get the suit of the card
* @return String
*/
public String getSuit()
{
return this.suit.toString();
}

/**
* Get the rank of the card
* @return String
*/
public String getRank()
{
return this.rank.toString();
}

/**
* Get the actual value of the card
* @return int
*/
public int getValue()
{
return this.value;
}

}
先搞清楚enum 怎麼用~~
__________________
AMD Athlon 64 3000+
Asus A8N-E nfoce 4 empowered
Simems DDR 400 512MB *2
Benq 1640
---------------------------------
舊 2006-09-28, 09:28 AM #15
回應時引用此文章
Xforce離線中  


    回應


POPIN
主題工具

發表文章規則
不可以發起新主題
不可以回應主題
不可以上傳附加檔案
不可以編輯您的文章

vB 代碼打開
[IMG]代碼打開
HTML代碼關閉



所有的時間均為GMT +8。 現在的時間是09:36 AM.


vBulletin Version 3.0.1
powered_by_vbulletin 2025。