I need help to write this program! Problem Description: Using the steps for Prob
ID: 3759539 • Letter: I
Question
I need help to write this program!
Problem Description:
Using the steps for Problem Solving - generate for the following problem:
a) test plan AND
b) write and test the program code in Java.
This problem will simulate a game of Solitaire Dice (an invented game). You are welcome to customize the game to your own rules – just be sure to document them. However, you must meet the basic requirements which follow.
The user will start with a pot of money of $50.
In each play of the game, the player will o Enter a valid bet amount (less than or equal to the current pot, not negative, a bet of 0 means quit the game).
The game will then remove their bet amount from the pot
The game will then roll three die (simulate this using the Random class in Java) display the values and add these values to a total.
Then, the game should adjust the pot in the following way:
If the total of the three dice is greater than 12, then the player wins their bet back.
If two of the three die have the same value, then the player wins double their bet back.
If all three die have the same value, then the player wins triple their bet back.
Otherwise, the player has lost their money.
The game will end with a bet of 0 OR when the pot reaches 0.
Design of this solution will involve three classes:
Die class – this class will represent ONE die – with a field of dieValue, a constructor, methods rollDie()(which gets random value as rolled value and returns it) and displayDie()
Game class – this class will represent the game- with fields of potAmount and betAmount and a constructor, methods getBetAmountFromUser(), and playGame().Note the playGame() method will have three local reference variables referring to three different objects of Die class to represent the three dice in the game.
Assign3 class – this class will be the "driver" class and have method main which will create an object of Game class, and execute the playGame() method
Sample Output : (blue indicates user entered information)
Welcome to Solitaire Dice Game. Bet an amount - if the sum of the three die is greater than 12, you keep your bet, if you roll doubles you win double your bet, if you roll triples you win triple your bet, otherwise you lose your bet. A bet of 0 ends the game.
Your current pot is 50
Enter your bet amount: 10
Your die are: 3 and 6 and 5
You WIN...your bet back
Your current pot is 50
Enter your bet amount: 10
Your die are: 3 and 6 and 6
You WIN....double your bet
Your current pot is 60
Enter your bet amount: 10
Your die are: 6 and 4 and 6 You WIN....double your bet
Your current pot is 70
Enter your bet amount: 100
Error - cannot bet less than 0 or more than 70...Enter your bet amount: 60
Your die are: 1 and 6 and 2
You LOSE....your bet
Your current pot is 10
Enter your bet amount: 0
You end the game with pot of 10
Explanation / Answer
import java.util.Scanner;
public class Game {
int potAmount = 50;
int betAmount;
Die dice1 = new Die();
public void getBetAmountFromUser(){
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Solitaire Dice Game. Bet an amount - if you roll 12 or over, you keep your bet, if you roll doubles you win double your bet, if you roll triples you win triple your bet, otherwise you lose your bet A bet of 0 ends the game");
System.out.println();
System.out.println("Your current pot is " + potAmount);
System.out.print("Enter your bet amount: ");
betAmount = input.nextInt();
while (betAmount<0 || betAmount>potAmount){
System.out.println("Error - cannot bet less than 0 or more than " + potAmount + "...Enter your bet amount: ");
betAmount = input.nextInt();
}
if (dice1.diceTotal>=12) {
System.out.println("You WIN....your bet back");
}
else if (dice1.diceRollOne == dice1.diceRollTwo || dice1.diceRollOne == dice1.diceRollThree || dice1.diceRollTwo == dice1.diceRollThree) {
System.out.println("You WIN....double your bet");
betAmount= (betAmount*2);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.