Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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 a new deck is opened and shued.

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

they have.

The Dealer gets a new deck and shues it. This will be done by choosing two cards from the new

deck (at random positions) and swapping their locatiions.

The Dealer then deals a hand to the player, by giving the player 4 cards selected sequentially from

the shued 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 dierent 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 ve 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 nal report stateing:

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 o 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 denition 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 - lling 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 void dealHand(int [] deck, int[] hand)

Initialize deck - initDeck()

Shue deck - shuffleDeck()

Uses the rst four values in deck to assign the four values of hand

Sort hand - sortHand()

{ 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.

3. Consider sorting the hand Array, to make your "is" methods easier to write.

Sample run(s):

Welcome to 4 Card Poker

Your initial bank roll is $100.00

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

Do you want to play a game? y

Place your bet [1, 100] : 101

Place your bet [1, 100] : 0

Place your bet [1, 100] : 2

Let the cards fall where they may ...

1 1 2 2

Let's get things in order ...

2 2 1 1

Congrats: You got 2 Pair and have won $44.

Do you want to play a game? y

Place your bet [1, 144] : 20

Let the cards fall where they may ...

9 1 9 7

Let's get things in order ...

9 9 7 1

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

Do you want to play a game? y

Place your bet [1, 164] : 100

Let the cards fall where they may ...

5 7 1 9

Let's get things in order ...

9 7 5 1

Sorry: you got Bubkiss and have lost $100.

Do you want to play a game? y

Place your bet [1, 64] : 64

Let the cards fall where they may ...

8 2 6 9

Let's get things in order ...

9 8 6 2

Sorry: you got Bubkiss and have lost $64.

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

Party's Over:you are out of chips.

Thanks for playing ...

You played a total of 4 hands.

Of which, you won 2.

And you lost 2.

But in the end you lost $100.

Java, Programming

  • Category:- Java
  • Reference No.:- M9454077

Have any Question?


Related Questions in Java

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As