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

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

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

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

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

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 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