ROLL THE DIE This program allows the user to enter an amount intheir bank, how m
ID: 3613946 • Letter: R
Question
ROLL THE DIE This program allows the user to enter an amount intheir bank, how many games they would like to play, enter in a bet,enter in a guess between 1-6, then display currentstatus. After when the program executes, it will displaywheather or not the user guess the number right or wrong.If right, the bet will be added to the current bank anddisplay it. If wrong, the bet will deduct from thecurrent bank and display it.Im using jGrasp and I have done most of the program, I justhave these two problems. Any questions, please send me message.Thanks!
My Problem: 1) (Bold Comment 1) The loop for how many games the user wantsto play does not loop correctly. If the user puts 2, the loop willexecute 3 times. If the user puts 4, the loop will execute 5 timesand so on. 2) (Bold Comment 2) This loop suppose to go through everytimethe userBet is <10 and >100, if not it just goes on. _________________________________________________________________________________________
import java.util.Scanner; import java.util.Random;
public class RollTheDie { public static void main (String[] args) { final int MIN_BET = 10, MAX_BET = 100; int userBank, userBet, userGame, userGuess, dieNum, count =0; Random generator = new Random(); Scanner scan = new Scanner (System.in); System.out.println ("Please enter the amount add to thebank:"); userBank = scan.nextInt(); System.out.println ("How many game would you like toplay?"); userGame = scan.nextInt(); //if the userGame is 2, it loops 3 times not 2 and soon while (count <= userGame) { System.out.println ("Enter your bet:"); userBet = scan.nextInt();
//this loop always goes through two times no matterwhat the userBet is while(userBet <= MIN_BET && userBet >=MAX_BET); { System.out.println ("Enter a bet between 10 and 100" + " and less than or equal to your bank of " + userBank); userBet = scan.nextInt(); } dieNum = generator.nextInt(6) + 1; System.out.println ("Enter your guess:"); userGuess = scan.nextInt(); if (userGuess != dieNum) { System.out.println ("Your Bank = " +(userBank-userBet)); System.out.println ("The corect guess was: " + dieNum); System.exit } else { System.out.println ("Your Bank = " +(userBank+userBet)); System.out.println ("Correct guess!"); } count++; }//End of counter loop System.out.println ("Thanks for playing Chris's dicegame!"); }//End of main }//End of class ROLL THE DIE This program allows the user to enter an amount intheir bank, how many games they would like to play, enter in a bet,enter in a guess between 1-6, then display currentstatus. After when the program executes, it will displaywheather or not the user guess the number right or wrong.If right, the bet will be added to the current bank anddisplay it. If wrong, the bet will deduct from thecurrent bank and display it.
Im using jGrasp and I have done most of the program, I justhave these two problems. Any questions, please send me message.Thanks!
My Problem: 1) (Bold Comment 1) The loop for how many games the user wantsto play does not loop correctly. If the user puts 2, the loop willexecute 3 times. If the user puts 4, the loop will execute 5 timesand so on. 2) (Bold Comment 2) This loop suppose to go through everytimethe userBet is <10 and >100, if not it just goes on. _________________________________________________________________________________________
import java.util.Scanner; import java.util.Random;
public class RollTheDie { public static void main (String[] args) { final int MIN_BET = 10, MAX_BET = 100; int userBank, userBet, userGame, userGuess, dieNum, count =0; Random generator = new Random(); Scanner scan = new Scanner (System.in); System.out.println ("Please enter the amount add to thebank:"); userBank = scan.nextInt(); System.out.println ("How many game would you like toplay?"); userGame = scan.nextInt(); //if the userGame is 2, it loops 3 times not 2 and soon while (count <= userGame) { System.out.println ("Enter your bet:"); userBet = scan.nextInt();
//this loop always goes through two times no matterwhat the userBet is while(userBet <= MIN_BET && userBet >=MAX_BET); { System.out.println ("Enter a bet between 10 and 100" + " and less than or equal to your bank of " + userBank); userBet = scan.nextInt(); } dieNum = generator.nextInt(6) + 1; System.out.println ("Enter your guess:"); userGuess = scan.nextInt(); if (userGuess != dieNum) { System.out.println ("Your Bank = " +(userBank-userBet)); System.out.println ("The corect guess was: " + dieNum); System.exit } else { System.out.println ("Your Bank = " +(userBank+userBet)); System.out.println ("Correct guess!"); } count++; }//End of counter loop System.out.println ("Thanks for playing Chris's dicegame!"); }//End of main }//End of class
Explanation / Answer
please rate - thanks I made some more changes to the lines inred-I think I highlighted them all import java.util.Scanner; import java.util.Random; public class RollTheDie { public static void main (String[] args) { final int MIN_BET = 10, MAX_BET = 100; int userBank, userBet, userGame, userGuess, dieNum, count = 0; Random generator = new Random(); Scanner scan = new Scanner (System.in); System.out.println ("Please enter the amount add to thebank:"); userBank = scan.nextInt(); System.out.println ("How many game would you like to play?"); userGame = scan.nextInt(); //if the userGame is 2, it loops 3 times not 2 and so on while (countRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.