Question: write this in java. You will write a simple dice game. The game starts by giving the player $ 2 5 0 . The game
write this in java. You will write a simple dice game. The game starts by giving the player $ The game prompts the player for the amount they want to bet and the sum of two randomly rolled die. If the player guess the sum correctly, the player wins some money based on the rules below. If the player guesses wrong, the player loses the amount that was bet. The game repeats until either the player runs out of money or the player chooses to stop playing.
Here are the rules for winning and losing.
If the guess matches the sum of the die and the two die have the same value, the winning is four times the bet. For example, if the player bet $ and the player guesses four as the sum and first dice is two and second dice is two, then the player is awarded $ which is twice the bet of $
If the guess matches the sum of the dice but the two die have different values, then the winning amount is the same as the bet.
If the player guesses the sum incorrectly, he loses the amount equal to the bet.
Input validation:
Make sure the player does not bet more than they have or a negative amount. If the amount is negative or greater than the amount they have, ask the player to reenter the bet.
Make sure the player types Y y N or n when prompted to continue the game. If the player enters anything else, the game should ask the player to reenter the answer.
Session History
When the program terminates, it should write the history of the game session to a file as below. If the file exists, the file will be overwritten. The history shows that the user played rounds, won three rounds but lost all at the third round as shown in the balance.
sum guess balance
Hints
Because this program is large, you will want to start out small. Below are the steps I suggest you can follow:
Print the dice banner will need escape sequence
Generate two random numbers
Let the user play a single round
Apply the rules so balance is updated correctly.
Let the user play unlimited number of rounds
Prompts user whether to continue
Deal with the case when the user is out of money
Add file writing
Add input validation
Sample : Input Validation
Welcome to Dice Game
:
You are given $ to start with
You can't play once you are out of money
How much are you betting?
How much are you betting?
How much are you betting?
Rolling the dice...
What is the sum of the two dice?
What is the sum of the two dice?
What is the sum of the two dice?
What is the sum of the two dice?
What is the sum of the two dice?
Die is
Die is
You lost $
Your current balance is $
Do you want another game? YN: a
Do you want another game? YN: b
Do you want another game? YN: n
Bye
Sample run : Out of money
Welcome to Dice Game
:
You are given $ to start with
You can't play once you are out of money
How much are you betting? H HH HH H
Rolling the dice...
What is the sum of the two dice?
Die is
Die is
You lost $
Your current balance is $
Sorry, you are out of money.
See you later.
Sample run : Winning
Welcome to Dice Game
:
You are given $ to start with
You can't play once you are out of money
How much are you betting?
Rolling the dice...
What is the sum of the two dice?
Die is
Die is
You won $
Your current balance is $
Do you want another game? YN: y
How much are you betting?
Rolling the dice...
What is the sum of the two dice?
Die is
Die is
You won $
Your current balance is $
Do you want another game? YN: n
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
