Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java question really really really needs help please. If you need more additional information about this problem, please let me know in the comments. Your

Java question really really really needs help please.

If you need more additional information about this problem, please let me know in the comments.

image text in transcribed

Your code should start with the following as shown:

image text in transcribed

image text in transcribed

Your code must contain all the methods listed below:

static void displayStats(int[] stats)

Prints statistics from multiple trials of evaluated poker hands.

static int evaluateOnePokerHand()

Deals a hand of poker from a new, shuffled deck, and returns an int representing the type of hand that was dealt.

static boolean hasFlush(Card[] hand)

returns whether a hand of 5 cards contains a flush (all cards having the same suit)

static boolean hasFourOfAKind(Card[] hand)

returns whether a 5-card hand contains 4 cards that are the same value

static boolean hasFullHouse(Card[] hand)

returns whether a 5-card hand contains a full house (3 of a kind in one value, and a pair of another value)

static boolean hasOnePair(Card[] hand)

returns whether a 5-card hand contains a pair of cards with the same value.

static boolean hasRoyalFlush(Card[] hand)

returns whether a 5-card hand contains a royal flush (an Ace-high straight flush)

static boolean hasStraight(Card[] hand)

returns whether a hand of 5 cards contains a straight (5 cards in sequence).

static boolean hasStraightFlush(Card[] hand)

returns whether a 5-card hand contains a straight flush (both a straight and a flush)

static boolean hasThreeOfAKind(Card[] hand)

returns whether a 5-card hand contains at least 3 cards that are the same value

static boolean hasTwoPair(Card[] hand)

returns whether a 5-card hand contains 2 pairs of matching values.

static void main(java.lang.String[] args)
static java.lang.String makeString(Card[] hand)

Returns a space delimited string of the cards in a poker hand, useful for debugging and testing hands.

static Card[] randomSortedHand()

Returns one random 5-card poker hand, sorted by value.

static int[] runSimulations(int n)

Runs n simulations of evaluating poker hands, returning an array of size 10 that contains the accumulated statistics for those simulations, starting with the number of high-card hands, one-pair hands, and so on, all the way up to the number of royal-flush hands

static void sort(Card[] hand)

Sorts an array of cards by value, with aces before 2, 3, 4, and so on, and J, Q, K as the three highest values.

And here is the tester so you can check your java code if it is correct:

public class PokerSimulatorTester {

public static void main(String[] args) {

try { int[] r = PokerSimulator.runSimulations(10); int i = PokerSimulator.evaluateOnePokerHand(); Card[] cards = { new Card(Card.ACE, Card.CLUBS), new Card(5, Card.HEARTS), new Card(3, Card.CLUBS), new Card(Card.QUEEN, Card.SPADES), new Card(Card.JACK, Card.DIAMONDS), };

PokerSimulator.sort(cards); String s = PokerSimulator.makeString(cards); Card[] h = PokerSimulator.randomSortedHand();

boolean b; b = PokerSimulator.hasFlush(cards); b = PokerSimulator.hasFourOfAKind(cards); b = PokerSimulator.hasFullHouse(cards); b = PokerSimulator.hasOnePair(cards); b = PokerSimulator.hasRoyalFlush(cards); b = PokerSimulator.hasStraight(cards); b = PokerSimulator.hasStraightFlush(cards); b = PokerSimulator.hasThreeOfAKind(cards); b = PokerSimulator.hasTwoPair(cards);

PokerSimulator.displayStats(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); } catch (Exception e) { System.out.println("An exception was thrown."); } System.out.println("If you see this message, your program" + " has all the required methods."); System.out.println( "Note that this doesn't test that your" + " methods do the right thing...only that the methods exist.");

}

}

Problem: Write a program that deals several poker hands, classifies each hand, presents a summary of the results, and notes the time it took to analyze those hands. Here is a sample run of the program: How many poker hands should I deal? 3000000 High card: One pair: Two pair: Three of a kind: Straight: Flush: Full house: Four of a kind: Straight flush: Royal flush: 1,503,296 50.1099% 1,267,847 42.2616% 142,514 4.7505% 63,555 2.1185% 11,707 0.3902% 5, 984 , 1995% 4,374 . 1458% 693 0.02 31% 29 0.0010% 1 0.0000% 3,000,000 hands were analyzed in 4.4333 seconds Background: In the game of poker, 5-card hands are dealt to players. Players bet on those hands based on the "ranks" of the hands. There are 10 possible ranks for the hands. They are, from lowest to highest: No pair (also known as "high card"), One pair, Two pairs, Three of a kind, Straight, Flush, Full house, Four of a kind, Straight flush, Royal flush This list of hand ranks is based on the probability of achieving each kind of hand. For example, there is roughly a 42% chance that a hand will contain "one pair", which is why it is ranked so much lower than a "royal flush" which has roughly a 0.000154% chance of occurring. There is a good Wikipedia article that describes the various hands, and includes their probabilities. It is worthwhile to visit ability. The probabilities in this article could be a useful way to check the performance of your program. Notice that a given hand may have more than one of the above ranks, in which case it is classified by its highest rank. So, for example, if a hand is "four of a kind", then it also meets the requirements for "three of a kind" and "two pair" and "one pair". However, such a hand would be classified as "four of a kind" because that is the highest possible rank. public class PokerSimulator f // Constants to define the various hand types public static final int HIGH-CARD = ; public static final int ONE PAIR = 1; public static final int TWO PAIR 2; public static final int THREE_OF_A_KIND3; public static final int STRAIGHT 4; public static final int FLUSH = 5; public static final int FULL-HOUSE-6; public static final int FOUR-OF-A-KIND = 7; public static final int STRAIGHT-FLUSH = 8; public static final int ROYAL-FLUSH = 9; Each poker hand that you deal should be represented by an array of 5 Card objects, and those cards should come from a shuffled Deck object. Each time you deal a new poker hand, you should begin with a fresh deck of cards (either by creating a new Deck each time, or by resetting the current d

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

Students also viewed these Databases questions