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;
}
}
}
}
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; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.