Question: I need help fixing the errors in my code. /** * Write a description of class CountRank here. * * @author (your name) * @version
I need help fixing the errors in my code.
/** * Write a description of class CountRank here. * * @author (your name) * @version (a version number or a date) */
import java.util.*;
public class countRank{
private int rankCount[]; private Hand hand; private int count ; public countRank(Hand h){ hand = h; rankCount = new int[15]; count = 15; for(int i=0;i<15;i++){ rankCount[i] = 0; } for(Card card: h.cards){ rankCount[card.getRank()] += 1; } } public boolean fourOfAKind(){ for(int i=2;i public boolean noPair(){ } public boolean onePair(){ if(countPairs() == 1){ return true; } return false; } public boolean twoPair(){ if(countPairs() == 2){ return true; } return false; } public boolean threeOfAKind(){ for(int i=2;i class Hand { public ArrayList cards = new ArrayList } public Hand(Card first, Card second, Card third, Card fourth, Card fifth){ cards[0] = first; cards[1] = second; cards[2] = third; cards[3] = fourth; cards[4] = fifth; } public Card getCard(int i){ return cards[i]; } public int category(){ } // Adds a card to the end of the hand public void addCard(Card card) { if (cards.size() != 5) cards.add(card); } // Returns cards in a string format public String toString() { return cards.toString(); } } class Card { // Instance variables private final int rank; private final int suit; // Constant variables for suit names private final static int CLUBS = 0; private final static int DIAMONDS = 1; private final static int HEARTS = 2; private final static int SPADES = 3; public Card(int rank, int suit) { this.rank = rank; this.suit = suit; } // Returns the rank public int getRank() { return this.rank; } // Sets the rank public void setRank(int rank) { rank = rank; } // Returns the suit public int getSuit() { return this.suit; } // Sets the suit public void setSuit(int suit) { suit = suit; } // Formats the card using unicode public String toString() { String out = " "; // Uses unicode for each suit depending on the card if (suit == CLUBS) out += '\u2663'; // Unicode char for black club else if (suit == DIAMONDS) out += '\u2662'; // white diamond. Closest to red else if (suit == HEARTS) out += '\u2661'; // white heart else if (suit == SPADES) out += '\u2660'; // black spade // If the rank is below 11, uses the actual number if (rank < 11) out += rank; else if (rank == 11) out += 'J'; else if (rank == 12) out += 'Q'; else if (rank == 13) out += 'K'; else out += 'A'; return out; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
