Question

Please try to not use array lists Main topics: Random number generators Arrays Programmer defined methods...

Please try to not use array lists

Main topics:

Random number generators

Arrays

Programmer defined methods

Program Specification:

You are to develop a program to play a variation on a game of chance called single player Poker.

Game Description:

• There is a Player who starts with 100 chips, each worth $1.00.

• There is a deck of 36 cards:

– Each card has a number in the range of [1, 9] printed on it

- 9 possible values / cards.

– There are 4 identical copies of each possible value / card - 36 cards in all.

– Before each hand is dealt, it is verified that there are enough cards in the existing deck, otherwise a new deck is opened and shuffled.

• A Dealer asks the Player to place a bet, the Player can bet anywhere from one to as many chips as they have.

• If needed, the Dealer gets a new deck and shuffles it. This is done by (repeatedly) choosing two cards from the new deck (at random positions) and swapping their locations.

• The Dealer then deals a hand to the player, by giving the player 4 cards selected sequentially from the shuffled deck described above.

• A determination is then made as to whether the Player has won or lost as such:

1. 4 of a kind If the number on each of the players’ four cards is the same then the player gets their bet back and in addition wins 6545 chips for each chip that was placed in that bet.

2. 3 of a kind If the number on exactly three of the players’ four cards is the same then the player gets their bet back and in addition wins 51 chips for each chip that was placed in that bet.

3. Straight If the number on the players’ four cards can be arranged so that they form a consecutive 4 number sequence then the player gets their bet back and in addition wins 38 chips for each chip that was placed in that bet.

4. Two Pair If the number on two of the players’ four cards is the same and the number on the remaining two cards is also the same yet the number on all four cards in not the same then the player gets their bet back and in addition wins 22 chips for each chip that was placed in that bet.

5. Pair - 2 of a kind If the number on exactly two of the players’ four cards is the same and the number on the remaining two cards are different then the player gets their bet back and in addition wins 1 chip for each chip that was placed in that bet.

6. Bubkiss If the players’ cards do not constitute one of the above five hands then the player losses - does not get their bet back.

• A report of the players’ new chip total is made.

• This process repeats as long as the Player still has any chips and wishes to play.

• A final report stating:

1. How many hands the Player played.

2. How bets the Player won.

3. How bets the Player lost.

4. The net winnings (or net losings) of the Player - Based off of starting with 100 chips.

Rules and Requirements:

• All user input must be validated.

• You must represent the deck of cards using an Array of ints (of size 36).

• You must represent the players hand using an Array of ints (of size 4).

• The following method definition is being provided for you to be called in your dealHand() method below:

public static void sortHand(int[] hand)

{

for (int i = 0; i < hand.length; ++i)

{

int maxLoc = i;

for (int j = i+1; j < hand.length; ++j)

if (hand[j] > hand[maxLoc])

maxLoc = j;

int tmp = hand[i];

hand[i] = hand[maxLoc];

hand[maxLoc] = tmp;

}

}

• For each of the following headings / descriptions, write and use a method that adheres to it:

– public static void initDeck(int[] deck)

Assign the elements of deck the values 1 to 9 four times, consecutively - filling the array.

– public static void shuffleDeck(int[] deck, int n)

The following is performed exactly n times:

Generate two random numbers (index1, index2) in the range 0 to 35 inclusive and then swap the value of array element at index1 with the value of the array element at index2

– public static int dealHand(int [] deck, int nextCard, int[] hand)

If there are at least four cards left in deck - base on the value of nextCard:

∗ Uses the four values in deck (starting at location nextCard) to assign the four values of hand

∗ Sort hand - sortHand()

∗ return the value of nextCard + 4

Else

∗ Initialize deck - initDeck() ∗ Shuffle deck - shuffleDeck()

∗ Uses the first four values in deck to assign the four values of hand ∗ Sort hand - sortHand()

∗ return the value 4

– public static void displayHand(int[] hand)

Prints the cards of hand in some reasonable report format.

– public static boolean isQuad(int[] hand)

Returns true if and only if the cards in hand qualify as 4 of a kind, returns false otherwise.

– public static boolean isTrip(int[] hand)

Returns true if and only if the cards in hand qualify as 3 of a kind, returns false otherwise.

– public static boolean isStraight(int[] hand)

Returns true if and only if the cards in hand qualify as a straight, returns false otherwise.

– public static boolean is2Pair(int[] hand)

Returns true if and only if the cards in hand qualify as two pair, returns false otherwise.

– public static boolean isPair(int[] hand)

Returns true if and only if the cards in hand qualify as a pair, returns false otherwise.

Notes and Hint:

1. Read the user’s option(s) as a String.

2. Use the String classes’ equalsIgnoreCase method for comparisons.

Sample run(s):

Welcome to 4 Card Poker

Your initial bank roll is $100.00

++++++++++++++++++++++++++++++++++++++++++++++

Play a hand [ y / n ] ? 5

Play a hand [ y / n ] ? gh

Play a hand [ y / n ] ? y

Place your bet [1, 100] : 101

Place your bet [1, 100] : -1

Place your bet [1, 100] : 10

... Shuffling Deck ...

Let the cards fall where they may ...

9 6 4 1

Sorry: you got Bubkiss and have lost $10.

Play a hand [ y / n ] ? y

Place your bet [1, 90] : 10

Let the cards fall where they may ...

8 7 5 4

Sorry: you got Bubkiss and have lost $10.

Play a hand [ y / n ] ? y

Place your bet [1, 80] : 10

Let the cards fall where they may ...

9 8 6 1

Sorry: you got Bubkiss and have lost $10.

Play a hand [ y / n ] ? y

Place your bet [1, 70] : 10

Let the cards fall where they may ...

5 2 2 1

Congrats: You got a Pair and have won $10.

Play a hand [ y / n ] ? y

Place your bet [1, 80] : 10

Let the cards fall where they may ...

9 5 3 3

Congrats: You got a Pair and have won $10.

Play a hand [ y / n ] ? y

Place your bet [1, 90] : 10

Let the cards fall where they may ...

7 5 3 2

Sorry: you got Bubkiss and have lost $10.

Play a hand [ y / n ] ? y

Place your bet [1, 80] : 10

Let the cards fall where they may ...

7 6 4 4

Congrats: You got a Pair and have won $10.

Play a hand [ y / n ] ? y

Place your bet [1, 90] : 10

Let the cards fall where they may ...

9 8 7 1

Sorry: you got Bubkiss and have lost $10.

Play a hand [ y / n ] ? y

Place your bet [1, 80] : 10

Let the cards fall where they may ...

8 6 3 2

Sorry: you got Bubkiss and have lost $10.

Play a hand [ y / n ] ? y

Place your bet [1, 70] : 10

... Shuffling Deck ...

Let the cards fall where they may ...

9 8 3 1

Sorry: you got Bubkiss and have lost $10.

Play a hand [ y / n ] ? n

+++++++++++++++++++++++++++++++++++++++++++

Thanks for playing ...

You played a total of 10 hands.

Of which, you won 3.

And you lost 7.

But in the end you lost $40.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Please try to not use array lists Main topics: Random number generators Arrays Programmer defined methods...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • How to I change this code to print the highest value(s) in the array? The wanted...

    How to I change this code to print the highest value(s) in the array? The wanted output (you just need to make it print the winner, ignore what comes before) is included below: -------------------------------------------------------------------------------------------- public static void playGame(int players, int cards) { if (players * cards > 52) { System.out.println("Not enough cards for that many players."); return; } boolean[] deck = new boolean[52]; int[] playerScore = new int[players]; for (int i = 0; i < players; i++) { System.out.println("Player "...

  • Complete a program In C#: some code is included, you edit the areas that have not...

    Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...

  • package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private...

    package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...

  • 2 A Game of UNO You are to develop an interactive game of UNO between a...

    2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...

  • the card game Acey Deucey, which is also known by several other names. In general, the...

    the card game Acey Deucey, which is also known by several other names. In general, the game is played with three or more people that continue to gamble for a pot of money. The pot grows and shrinks depending on how much General description of the game ● Two cards are dealt face up to a player from a shuffled deck of cards. ○ If the face of each card is the same then the player adds $1 into the...

  • C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data...

    C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int. 2. In main(), declare an array with space for 52 records, representing a deck of playing cards. 3. Define a function called initialize()...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT