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 $250. 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 $100 and the player guesses four as the sum and first dice is two and second dice is two, then the player is awarded $400, which is twice the bet of $100.
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 4 rounds, won three rounds but lost all at the third round as shown 0 in the balance.
sum guess balance
77350
74250
88500
1050
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 1: Input Validation
Welcome to Dice Game
____
/'.\_____
/: \___\/./\
\'/.//____/..\
\/___/''\/
'__'\/
You are given $250 to start with
You can't play once you are out of money
How much are you betting? -100
How much are you betting? 300
How much are you betting? 100
Rolling the dice...
What is the sum of the two dice? -3
What is the sum of the two dice? 0
What is the sum of the two dice? 1
What is the sum of the two dice? 13
What is the sum of the two dice? 8
Die 1 is 1
Die 2 is 2
You lost $100
Your current balance is $150
Do you want another game? Y/N: a
Do you want another game? Y/N: b
Do you want another game? Y/N: n
Bye
Sample run 2: Out of money
Welcome to Dice Game
____
/'.\_____
/: \___\/./\
\'/.//____/..\
\/___/''\/
'__'\/
You are given $250 to start with
You can't play once you are out of money
How much are you betting? 300^H ^H^H ^H^H ^H250
Rolling the dice...
What is the sum of the two dice? 8
Die 1 is 1
Die 2 is 4
You lost $250
Your current balance is $0
Sorry, you are out of money.
See you later.
Sample run 3: Winning
Welcome to Dice Game
____
/'.\_____
/: \___\/./\
\'/.//____/..\
\/___/''\/
'__'\/
You are given $250 to start with
You can't play once you are out of money
How much are you betting? 100
Rolling the dice...
What is the sum of the two dice? 10
Die 1 is 5
Die 2 is 5
You won $400
Your current balance is $650
Do you want another game? Y/N: y
How much are you betting? 100
Rolling the dice...
What is the sum of the two dice? 8
Die 1 is 3
Die 2 is 5
You won $100
Your current balance is $750
Do you want another game? Y/N: n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!