黑杰克游戏错误

时间:2012-11-19 00:52:21

标签: java class exception

我的黑杰克程序中有错误。我一直试着找了半个小时。它说“卡已经定义了”。由于某种原因,我的deal()函数也不能正常工作。我将再次发布此信息以获取更多信息。有人可以帮忙吗?我是初学者。 所以我有一个名为index的类,其主要方法是:

public static void main(String[] args){
    runGame(2);                                 
}

然后我有几个方法然后我跑了游戏:

public static void runGame(int n){
    Card[] newdeck=createCardArray();

    Card[] shuffleddeck = shuffle(newdeck); 
    Deck deck = new Deck(shuffleddeck);
    int[] players = createPlayers(n);
    int[] points = createPoints(n);


    for(int i = 0 ; i< players.length - 1; i++){
        Card a = deck.deal();
        Card b = deck.deal();
        updatePoints(players, points, i, a);
        updatePoints(players, points, i, b);
    }
    printPlayersPoints(players, points);
}

在该文件夹中我还有一个Card.class和Deck.class:如果你想看看我有以下链接。 当我运行这个我得到一个错误我不知道我做了什么,但它改变了:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The public type Deck must be defined in its own file
Syntax error on token "}", { expected
Syntax error on token(s), misplaced construct(s)
The public type Card must be defined in its own file
Syntax error on tokens, delete these tokens
The public type Blackjack must be defined in its own file
Syntax error on token "]", invalid (
Syntax error, insert "]" to complete ArrayAccess
Syntax error, insert ")" to complete MethodInvocation
Syntax error, insert ";" to complete Statement
GIO cannot be resolved
GIO cannot be resolved
GIO cannot be resolved
BlackjackWindow cannot be resolved to a type
BlackjackWindow cannot be resolved to a type
GIO cannot be resolved
BlackjackWindow cannot be resolved to a type
Syntax error on token "}", { expected
Syntax error on token(s), misplaced construct(s)
The public type Hand must be defined in its own file
Syntax error on tokens, delete these tokens
The public type Player must be defined in its own file
Syntax error, insert "}" to complete Block
BlackjackWindow cannot be resolved to a type
BlackjackWindow cannot be resolved to a type
GIO cannot be resolved
GIO cannot be resolved
BlackjackWindow cannot be resolved to a type
GIO cannot be resolved
GIO cannot be resolved
GIO cannot be resolved
GIO cannot be resolved
GIO cannot be resolved
Syntax error on token "}", { expected
Syntax error on tokens, delete these tokens
Syntax error, insert "}" to complete Block
Syntax error, insert "}" to complete ClassBody

at Card.<init>(fullblk.java:4)
at index.createCardArray(index.java:19)
at index.runGame(index.java:104)
at index.main(index.java:3)

但由于某种原因,这次我收到了这个错误:

    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The constructor Deck(Card[]) is undefined
    The method deal() is undefined for the type Deck
    The method deal() is undefined for the type Deck

    at index.runGame(index.java:101)
    at index.main(index.java:3)

任何人都可以帮助我。

  

index.java: http://pastebin.com/8x344TN9   Card.java: http://pastebin.com/NLbHBDSi   Deck.java:http://pastebin.com/emD75yv0

3 个答案:

答案 0 :(得分:2)

甲板课结束时的支撑问题:

public class Deck
{
    // your constructors and methods.
  }
}

答案 1 :(得分:1)

你在Deck.java的末尾有一个额外的大括号('}')。

答案 2 :(得分:0)

好吧,你在Deck类的末尾有一个额外的}(右括号),删除那个结束括号编译。你应该好。

public class Deck
{
    // your constructors and methods.
  }
}