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

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

  回應
 
主題工具
paradise
Golden Member
 

加入日期: Apr 2001
文章: 2,513
java 裡的 enum type

要寫一個簡單的撲克牌 class
裡面的 rank 和花色想用 enum 來表示
網上查了一下用法 就開始在 eclipse 著手寫
但是就是錯誤百出

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

public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }

明明 example 上的 syntax 就是長這樣
但是在 eclipse 裡就是一堆 error
說要 ;
Rank 也被畫紅線
又指出沒 enum 這個 type
我已經有 import java.util.*;
但是還是沒有辦法解決

有人能指教一下嗎 感謝!
     
      

此文章於 2006-09-27 11:14 PM 被 paradise 編輯.
舊 2006-09-27, 11:13 PM #1
回應時引用此文章
paradise離線中  
chlang
Master Member
 
chlang的大頭照
 

加入日期: Dec 2001
文章: 1,747
也許 您的 Compiler Version 沒有指定好.

Window -> Prefences ->Java -> Compiler ->JDK Compliance ....
 
舊 2006-09-27, 11:48 PM #2
回應時引用此文章
chlang離線中  
paradise
Golden Member
 

加入日期: Apr 2001
文章: 2,513
引用:
作者chlang
也許 您的 Compiler Version 沒有指定好.

Window -> Prefences ->Java -> Compiler ->JDK Compliance ....


應該不是這個問題
因為我連 compile 都還沒開始
只是在寫的時候 eclipse 跳出來的 syntax error
舊 2006-09-27, 11:57 PM #3
回應時引用此文章
paradise離線中  
誰找我
Major Member
 
誰找我的大頭照
 

加入日期: Aug 2005
您的住址: 歡迎加入THK
文章: 161
也許應該在enum的{}結尾加個分號;...
舊 2006-09-28, 12:09 AM #4
回應時引用此文章
誰找我離線中  
MOSWU
Advance Member
 

加入日期: May 2005
文章: 433
引用:
作者paradise
應該不是這個問題
因為我連 compile 都還沒開始
只是在寫的時候 eclipse 跳出來的 syntax error

剛剛試了一下上面的程式碼
沒有問題(我也是用eclipse)

能否附上完整的程式碼?
舊 2006-09-28, 12:27 AM #5
回應時引用此文章
MOSWU離線中  
paradise
Golden Member
 

加入日期: Apr 2001
文章: 2,513
引用:
作者MOSWU
剛剛試了一下上面的程式碼
沒有問題(我也是用eclipse)

能否附上完整的程式碼?


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;
this.rank = rank;
this.value = value;
}

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

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

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



}

才剛開始 還沒寫出甚麼
更別說是 compile
但是光這樣 eclipse 就出現煩人的 syntax error
請大家再幫忙一下 感謝
舊 2006-09-28, 01:55 AM #6
回應時引用此文章
paradise離線中  
paradise
Golden Member
 

加入日期: Apr 2001
文章: 2,513
引用:
作者誰找我
也許應該在enum的{}結尾加個分號;...


這個試過 也是不行
試過把 enum 改成 Enum 就會少一個錯誤
但是其它的還是錯的亂七八遭..
舊 2006-09-28, 01:58 AM #7
回應時引用此文章
paradise離線中  
chlang
Master Member
 
chlang的大頭照
 

加入日期: Dec 2001
文章: 1,747
你的 JDK 應該是 1.5 或者以後吧 ?

如果不是 ^^;
舊 2006-09-28, 02:47 AM #8
回應時引用此文章
chlang離線中  
paradise
Golden Member
 

加入日期: Apr 2001
文章: 2,513
引用:
作者chlang
你的 JDK 應該是 1.5 或者以後吧 ?

如果不是 ^^;


是 1.5.0.03

這位同學 別說話說一半啊
舊 2006-09-28, 03:05 AM #9
回應時引用此文章
paradise離線中  
MOSWU
Advance Member
 

加入日期: May 2005
文章: 433
剛剛又把你的程式試了一下
enum宣告依然沒有問題
有問題的是後面像是 this.suit = suit;型別錯誤的地方

看來幫不上什麼忙了,sorry
舊 2006-09-28, 08:32 AM #10
回應時引用此文章
MOSWU離線中  


    回應


POPIN
主題工具

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

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



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


vBulletin Version 3.0.1
powered_by_vbulletin 2025。