What is wrong with this program?

// The game of Go Fish

public class GoFish {

public static final Scanner INPUT = new Scanner(System.in); // For reading from the console

private GoFishHand computerHand; // The computer's hand of Cards

private int computerScore; // Number of sets of four the computer has laid down

private Deck deck; // The Deck

private GoFishHand playerHand; // The player's hand of Cards

private int playerScore; // Number of sets of four the player has laid down

public GoFish() // Shuffle the Deck and deal seven Cards to each player
{
computerScore = 0;
playerScore = 0;
deck = new Deck();
deck.shuffle();
computerHand = new GoFishHand();
playerHand = new GoFishHand();
for (int i = 0; i < 7; i++) {
playerHand.add(deck.deal());
computerHand.add(deck.deal());
}
}


public boolean computerTurn() // Take a turn for the computer. Return true if the computer has earned a bonus turn.
{
if (computerHand.isEmpty() && !(deck.isEmpty())) {
computerHand.add(deck.deal());
}
System.out.println("\n" + this);
int rank = ((int)(Math.random() * 13)) + 1;
char rankCharacter = new Card(rank, Card.HEARTS).toString().charAt(0);
System.out.println("The computer asks for " + rankCharacter);
boolean bonusTurn = playerHand.give(rank, computerHand);
if (!bonusTurn) {
System.out.println("Go fish");
Card card = deck.deal();
computerHand.add(card);
if (card.getRank() == rank) { bonusTurn = true; }
}
int sets = computerHand.meldSets();
computerScore += sets;
if (sets > 0) {
System.out.println("The computer lays down " + sets
+ " sets, bringing its total to "
+ computerScore);
}
return bonusTurn;
}


public void play() // Play until either the player or the computer wins
{
while (playerScore + computerScore < 13) {
while ((playerScore + computerScore < 13) && (playerTurn())) {
}
while ((playerScore + computerScore < 13) && (computerTurn())) {
}
}
System.out.println("The computer made " + computerScore + " sets");
System.out.println("You made " + playerScore + " sets");
if (playerScore > computerScore) {
System.out.println("You win!");
} else {
System.out.println("The computer wins");
}
}


public boolean playerTurn() //Take a turn for the player. Return true if the player has earned a bonus turn.
{
if (playerHand.isEmpty() && !(deck.isEmpty())) {
playerHand.add(deck.deal());
}
System.out.println("\n" + this);
System.out.print("Which card will you ask for? ");
char cardName = INPUT.nextLine().toUpperCase().charAt(0);
int rank;
if (cardName == 'A') {
rank = Card.ACE;
} else if (cardName == 'T') {
rank = 10;
} else if (cardName == 'J') {
rank = Card.JACK;
} else if (cardName == 'Q') {
rank = Card.QUEEN;
} else if (cardName == 'K') {
rank = Card.KING;
} else {
rank = cardName - '0';
}
boolean bonusTurn = computerHand.give(rank, playerHand);
if (!bonusTurn) {
System.out.println("Go fish");
Card card = deck.deal();
System.out.println("You draw: " + card);
playerHand.add(card);
if (card.getRank() == rank) { bonusTurn = true; }
}
int sets = playerHand.meldSets();
playerScore += sets;
if (sets > 0) {
System.out.println("You lay down " + sets
+ " sets, bringing your total to "
+ playerScore);
}
return bonusTurn;
}

public String toString() {
String result = "There are " + deck.size() + " cards in the deck\n";
result += "The computer has " + computerHand.size() + " cards\n";
return result + "Your hand: " + playerHand;
}


public static void main(String[] args) // Create and play the game
{
System.out.println("Welcome to Go Fish.");
GoFish game = new GoFish();
game.play();
}

}



I'm unsure since it looks like a JAVA program. I can't even test it since I don't have a JAVA compiler. You're also on the wrong forum if you're trying to work with JAVA. This is for C and C++ only.
Yes I know. Thanks for the advice. I am just an enthusiast programming person and I try all programs
Topic archived. No new replies allowed.