Question: This is almost done. Please help me finish. Code below card.java public class Card { static private String suits = SHDC; static private String ranks

This is almost done. Please help me finish. Code below

This is almost done. Please help me finish. Code below card.java public

card.java public class Card { static private String suits = "SHDC"; static private String ranks = "23456789TJQKA"; static private String[] suitNames = {"Spades", "Hearts", "Diamonds", "Clubs"}; static private String[] rankNames = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"}; int rank; int suit; /** * An internal contructor for verified parameters. * * @param r the rank of the card to be constructed * @param s the suit of the card to be constructed */ private Card(int r, int s) { rank = r; suit = s; } /** * A contructor accepting case-insensitive string representations of the rank and suit of a card. * * @param r a one character representation of the rank, 23456789TJQKA * @param s a one character representation of the suit, SHDC */ Card(String r, String s) { int rr, ss; if (1 == r.length()) { rr = ranks.indexOf(r.toUpperCase()); if (rr >= 0) rank = rr; } else rank = 0; if (1 == s.length()) { ss = suits.indexOf(s.toUpperCase()); if (ss >= 0) suit = ss; } else suit = 3; } Card(Card c) { rank = c.rank; suit = c.suit; } /** * Computes a unique deck index for each card in a deck. * * @return the deck index from 0 to 51 */ int deckIndex() { return suit * ranks.length() + rank; } /** * Constructs a Card from a deck index. * * @param dx the deck index from 0 to 51 * @return a Card object with rank and suit corresponding to the deck index * @throws IllegalArgumentException if the deck index is out-of-range */ static Card factory(int dx) { int rr, ss; rr = rankNames.length; ss = suitNames.length; if (dx = rr * ss) throw new IllegalArgumentException(); return new Card(dx % rr, dx / rr); } int getRank() { return rank; } int getSuit() { return suit; } /** * Compute a String representation of this card. * * @return the String representation */ public String toString() { return rankNames[rank] + " of " + suitNames[suit]; } public String toShortString() { return ranks.charAt(rank) + " " + suits.charAt(suit); } }

//PokerHand.java

import java.util.Arrays; public class PokerHand { private Card[] hand; private Integer handRank; private String combination; public PokerHand(Card[] handDeal) { hand = handDeal; } //print rank&combination  public String toString() { System.out.println("The Hand Rank is "+ handRank); System.out.println("The Hand Combination is "+ combination); return "The Hand Rank is "+ handRank+ " The Hand Combination is "+ combination; } //  public Integer calculateRank() { Integer[] ranks = new Integer[5]; Character [] suits=new Character[5]; combination = "Nothing"; handRank = 0; Integer[] frequencyRanks = {1, 1, 1, 1, 1}; Integer[] frequencySuits = {1, 1, 1, 1, 1}; Integer sequence = 0; for(Integer i=0; ihand[i].rank; suits[i] = hand[i].suit; } Arrays.sort(ranks); Arrays.sort(suits); for(Integer i=0; iif(suits[i] == suits[i+1]) { frequencySuits[i] = frequencySuits[i] + 1; } } for(Integer i=0; iif(ranks[i] == ranks[i+1]) { frequencyRanks[i] = frequencyRanks[i] + 1; } if(ranks[i] == ranks[i+1] - 1) { sequence++; } } Integer count = 0; for(Integer i=0; iif(frequencyRanks[i] > 1) { count++; } } Integer countSuit = 0; for(Integer i=0; iif(frequencySuits[i] > 1) { countSuit++; } } //array and loop  Arrays.sort(frequencyRanks); Arrays.sort(frequencySuits); if(count == 1) { if(frequencyRanks[4] == 2) { combination = "One Pair"; handRank = 1; } else if(frequencyRanks[4] == 3) { combination = "Three of a Kind"; handRank = 3; } else if(frequencyRanks[4] == 4) { combination = "Four of a Kind"; handRank = 7; } } else if(count == 2) { if(frequencyRanks[4] == 2 && frequencyRanks[3] == 2) { combination = "Two Pair"; handRank = 2; } if(frequencyRanks[4] == 3 && frequencyRanks[3] == 2) { combination = "Full House"; handRank = 6; } } else if(count == 0 && sequence == 5) { combination = "Straight"; handRank = 4; } if(frequencySuits[4] == 5) { if(combination == "Nothing") { combination = "Flush"; handRank = 5; } else if(combination == "Straight") { combination = "Straight Flush"; handRank = 8; } } return handRank; } } 

In poker, a 5 card hand is ranked according to the highest of the following combinations of cards it contains. 0. Nothing the hand has none of the following combinations 1. One pair two of the cards have the same rank 2. Two Pair two of the cards have the same rank, and two of the other cards have the same rank which is different than the rank of the first pair 3. Three of a Kind three of the cards have the same rank 4. Straight the ranks of all 5 cards are in a sequence with no gaps (e.g. 7 8 9 10 J) (Ace is higher than King) 5. Flush the suits of all 5 cards are the same 6. Full House three of the cards have the same rank, and the remaining two cards also have the same rank 7. Four of a Kind four of the cards have the same rank 8. Straight Flush the ranks of all 5 cards are in a sequence and the suits are all the same For this assignment, write a PokerHand class (PokerHand.java) hose constructor accepts an array of 5 Cards (from the previous assignment), copies the cards into the Poker Hand instance, and ranks the hand The toString ethod of d should display the and and its rank see the example below) The attached file contains a number of poker hands, one hand per line. Each hand has five cards, each card is represented by two characters, as in the previous assignment. The first line in the file is a single number which is a count of the number of hands that follow The main0 ethod of PokerHand should read the hands, create an instance of PokerHand for each hand, and display it using PokerHand.toString0. Example output. 6 H 3 S 4 S 7 S 5 S Straight

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!