subject
Computers and Technology, 14.12.2019 03:31 loridoz

In order to discover that a poker hand has a straight, you must first search for the lowest card in the hand, then you must search for the next higher card, the card higher than that, and so on. for example, if the lowest card is a four, you must next search for a 5 in the hand, then a six, then a seven, and finally an eight. if any of these searches fails, then the card does not contain a straight.

note that a "wrap straight", which is defined as a straight that includes both a king and an ace by wrapping around the top of the card hierarchy is not considered a legitimate straight. therefore finding the lowest card and searching upwards is guaranteed to determine if a straight exists. this is not precisely the rule in all card games, but we will hold to it here to focus on the objective of the lesson.

the cards are to be represented using the numbers 0-51, where 0-12 are the diamonds, 13-25 are the clubs, 26-38 are the hearts, and the rest are the spades. in each suit, the lowest number is to correspond to the ace, the next lowest is the 2, and so on up until you reach the jack, queen and the king. a 5 card hand is to be represented as an array with 5 integers where no two can be the same. you should generate it by selecting the first 5 integers from a shuffled array of all 52 integers above. see lecture slides on shuffling an array.

step 1: write a method to generate a shuffled deck of cards represented as an array of 52 integers.

step 2: write a method that draws the first 5 card hand from a shuffled deck, represented as the first 5 cards in the array.

step 3: write a method that accepts a 5 card hand and an integer k as input. it should search for the kth lowest card. so if k is 1, it searches for the lowest card. if k is 2, it searches for the second lowest card, etc. if k is greater than 5 or less than zero, it returns an error. use linear search.

finally, write a method that calls the method in step 3 to search for your straight.

integrate straight() into a new main method that generates random hands. call straight() to determine if the random hands have a straight. perform this test on one million randomly generated hands, counting how frequently a straight is detected. according to wikipedia, the chance of drawing a straight is 0.3925%. your randomly generated hands are simulating this probability - do you observe the same percentage?

write your code in straight. java.

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:50, shadow29916
What is a rush associated with alcohol?
Answers: 1
image
Computers and Technology, 25.06.2019 12:10, uwrongboi
Create a function called quadform( ) that takes as input the coefficients of the quadratic equation (a, b,c) and returns the two distinct real roots (x1,x2) as output, if they exist. in addition, the function returns a message (flag) that informs the user if an error occurred when trying to find two distinct real roots. the possible errors are: (1) "only one root is found"; (2) "imaginary roots are found"; (3) "any value of x is a solution"; (4) "no zeroes exist." if no errors occur, then flag should be "no errors".
Answers: 1
image
Computers and Technology, 25.06.2019 22:00, beabivine7023
Iam doing microsoft excel and i have do formulas, can some explain to me how do them?
Answers: 1
image
Computers and Technology, 25.06.2019 23:00, fonsworth5
Edmund wants to create a website for his university. he has created all the necessary content and now wants to style and format the website. which language should he use? a. xml b. html c. css d. javascript
Answers: 2
You know the right answer?
In order to discover that a poker hand has a straight, you must first search for the lowest card in...

Questions in other subjects:

Konu
History, 15.04.2021 19:30
Konu
English, 15.04.2021 19:30
Konu
Mathematics, 15.04.2021 19:30