Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help make me run in java. Card.java is there for refrence. Please provide

ID: 3801660 • Letter: P

Question

Please help make me run in java. Card.java is there for refrence. Please provide picture of what it looks like when run. I can't figure it out. Please provide output if possible. Picture for refrence. ANy comments would be appriciated as well.

//card3.txt
11
6 H 3 S 4 S 7 S 5 S
9 S T S q s k s a H
2 H 3 H 5 H 2 C 5 S
8 H 9 H T H j h q h
k h k D 2 D 3 D 4 D
5 D 6 D 6 S 6 c 5 s
q d j d q C q S 5 C
6 C 8 C 9 C T C j c
2 c k c 2 S 2 h 2 D
4 H j s a D k d a C
5 S 6 S 2 S 3 S 4 S
//
How to Rank a Poker Hand

1. count the frequency of each rank and each suit in the hand
2. set hand rank to nothing
3. examine the frequencies of the ranks for the following cases
a. only one frequency is greater than 1
i. f == 2 - one pair
ii. f == 3 - three of a kind
iii. f == 4 - four of a kind
b. two frequencies are greater than 1
i. f1 == 2 and f2 == 2 - two pair
ii. f1 == 3 and f2 == 2 (or vice versa) - full house
c. all frequencies are one
i. check for all five cards in a sequence - straight
4. examine the frequencies of the suits
a. one suit occurs 5 times
i. if the rank is nothing - flush
ii. if the rank is straight - straight flush

//pokerHand.java

public class PokerHand {
private Card[] hand;
private integer handRank;
private String combination;

public PokerHand(Card[] handDeal) {
hand = handDeal;
}

public void toString() {
System.out.println('The Rank of the Hand is '+ handRank);
System.out.println('The Combination of the Hand is '+ combination);
}

public integer calculateRank() {
Integer[] ranks;
Char[] suits;
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; i<5; i++) {
ranks[i] = hand[i].rank;
suits[i] = hand[i].suit;
}
Arrays.sort(ranks);
Arrays.sort(suits);
for(integer i=0; i<5; i++) {
if(suits[i] == suits[i+1]) {
frequencySuits[i] = frequencySuits[i] + 1;
}
}
for(integer i=0; i<5; i++) {
if(ranks[i] == ranks[i+1]) {
frequencyRanks[i] = frequencyRanks[i] + 1;
}
if(rank[i] == rank[i+1] - 1) {
sequence++;
}
}
integer count = 0;
for(integer i=0; i<5; i++) {
if(frequencyRanks[i] > 1) {
count++;
}
}
integer countSuit = 0;
for(integer i=0; i<5; i++) {
if(frequencySuits[i] > 1) {
countSuit++;
}
}
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;
}
}
}
}

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

Explanation / Answer

/** * @fileName PokerHand.java * @author ravi * @since 22/3/17 */ package pokerhand; import java.util.Arrays; public class PokerHand { private Card[] hand; private Integer handRank; private String combination; public PokerHand(Card[] handDeal) { hand = handDeal; } public String toString() { System.out.println("The Rank of the Hand is "+ handRank); System.out.println("The Combination of the Hand is "+ combination); return "The Rank of the Hand is "+ handRank+ " The Combination of the Hand 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; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote