简体   繁体   中英

When i compile I keep getting this error message '.class' expected for this line this.hand = Card[] hand; I don't know what to do to change it

I looked on websites for help but I still can't find an answer to for this problem.

Here is the code:

import java.util.Scanner;

public class Player {

private Card[] hand;
private int placement;
private Strategy myStrategy;

public Player( Card hand, Strategy myStrategy ) {
    this.hand = Card[] hand;
    this.myStrategy = myStrategy;
    placement = 0;
}

public void giveCard( Card newCard ) {
    hand[placement] = new Card();
    placement++;
}

public int takeTurn() {
    return myStrategy.hitOrStand();
}

public int value() {
    int value = 0;

    for( int i = 0; i < placement; i++ ) {
        this.value = value + hand[i].value();
    }

    return value;
}
}

I'm so confused on how to change this. Can somebody help me to make sure that I have it right.

This statement

this.hand = Card[] hand;

is illegal. You could try

this.hand = new Card[] { hand };

NOTE You still have only room for one Card in your Hand array at that point. I recommend that you use a Collection type (I would probably use a Set or a List myself) for your hand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM