Knowee
Questions
Features
Study Tools

For the craps game in the tutorial, if code were implemented to input a bet for a player, what code segment would ensure that a bet with a maximum amount of 100 is received?a.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount < 0) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); playMultipleGames(number,betAmount); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in output b.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount < 0) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); if (betAmount > 100) playMultipleGames(number,betAmount); else System.out.println("Please enter a non-negative number for your bet."); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in outputc.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount > 100) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in output d.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount <= 100) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); if (betAmount <= 100) playMultipleGames(number,betAmount); else System.out.println("Please enter a non-negative number for your bet."); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in output

Question

For the craps game in the tutorial, if code were implemented to input a bet for a player, what code segment would ensure that a bet with a maximum amount of 100 is received?a.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount < 0) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); playMultipleGames(number,betAmount); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in output b.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount < 0) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); if (betAmount > 100) playMultipleGames(number,betAmount); else System.out.println("Please enter a non-negative number for your bet."); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in outputc.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount > 100) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in output d.) // Track if input of bet is valid int betAmount = -1; // Assume invalid input of number until it proves to be correct while(!betAmount <= 100) { try { System.out.print("Pass Line Bet : "); betAmount = input.nextInt(); if (betAmount <= 100) playMultipleGames(number,betAmount); else System.out.println("Please enter a non-negative number for your bet."); } catch(InputMismatchcatchion ex) { System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); // Clear out input to remove \n input.nextLine(); } } System.out.println(); // Add blank line in output

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct code segment that would ensure a bet with a maximum amount of 100 is received is:

d.)

// Track if input of bet is valid
int betAmount = -1; 
// Assume invalid input of number until it proves to be correct
while(betAmount <= 0 || betAmount > 100) { 
  try { 
    System.out.print("Pass Line Bet : "); 
    betAmount = input.nextInt(); 
    if (betAmount <= 100) 
      playMultipleGames(number,betAmount); 
    else 
      System.out.println("Please enter a non-negative number for your bet."); 
  } 
  catch(InputMismatchException ex) { 
    System.out.println("Not a valid bet. Please enter a number between 1-100 for your bet."); 
    // Clear out input to remove \n
    input.nextLine(); 
  } 
} 
System.out.println(); // Add blank line in output

This code segment first initializes betAmount to -1. Then it enters a while loop that continues until a valid bet amount is entered. The bet amount is considered valid if it is greater than 0 and less than or equal to 100. If the bet amount is valid, the playMultipleGames function is called with number and betAmount as arguments. If the bet amount is not valid, a message is printed to the console asking for a non-negative number for the bet. If the input is not an integer, an InputMismatchException is caught and a message is printed to the console asking for a number between 1 and 100 for the bet. The input is then cleared to remove the newline character. After the while loop, a blank line is printed to the console.

This problem has been solved

Similar Questions

For the craps game in the tutorial, the client may want to enter a cash amount to bet for each game. If they bet (e.g., $5) and win, they receive two times their bet ($10); if they lose, the money they bet (e.g., $5) goes to the casino.If you need to add the core logic to allow a player to bet in this way, what pseudocode accurately represents this task?a.)# Ask the player how much to bet#Play the game# If the player won the first game add double the bet to the total won# else the player lost so subtract the bet from the total wonb.)# Ask the player how much to bet per game#Play the game# If the player won add the bet to the total won# else the player lost so subtract the bet from the total wonc.)# Ask the player how much to bet#Play the game# If the player won add double the bet to the total won# If the player lost subtract double the bet from the total wond.)# Ask the player how much to bet per game# Play the game# If the player won the game add double the bet to the total won# else the player lost so subtract the bet from the total won

For this assignment you will write the first part of a program that will play a simple "Guess the Number" game. In the full version of this game (which you will write for this week's project) the program will randomly generate an integer between 1 and 200 inclusive and then will repeatedly ask the user for a guess. If they guess a number that is less than 1 or more than 200 an error message will be printed as a part of this loop. For this lab you will write the piece of the code that checks for this error and ends if the user picks the right number.Sample Output This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Note that the code for this lab includes a "debugging" output that starts with the word "DEBUG: " that tells you the number that was randomly chosen. In the full version of this program that will be removed, but for this incremental piece your lab submission should include it. (You should get used to having this kind of debugging output in your code that isn't part of the final program but is crucial to ensuring that each incremental piece is working properly before you move onto the next part of the program).If the user enters an invalid choice, your code should inform them that their choice was invalid and ask them to guess again.Enter a random seed: 99DEBUG: The number picked is: 188Enter a guess between 1 and 200: 259Your guess is out of range. Pick a number between 1 and 200.That is not the number.Enter a guess between 1 and 200: -1Your guess is out of range. Pick a number between 1 and 200.That is not the number.Enter a guess between 1 and 200: 88That is not the number.Enter a guess between 1 and 200: 188Congratulations! Your guess was correct!I had chosen 188 as the target number.You guessed it in 4 tries.Random numbers: Just like in the FunWithBranching programming assignment, you must use the Random class to generate numbers between 1 and 200. Make sure you are using int values and not doubles for this assignment! Look back at your submitted code for that project and reuse what you can here - reusing code from old assignments isn't only allowed, it's ENCOURAGED! If you've solved a problem once you should remind yourself how you solved it when asked to do something similar!

Write a program to accept marks from 1-100as input from user. If the user enters <40as an input or if user enters any negative number, or >100  user defined exception should begenerated.

Which of the following is NOT an acceptable input validation technique for a player's choice in a Rock, Paper, Scissors game?1 pointUsing a try-except block to catch invalid inputsAsking the player to enter a number instead of a choiceProviding a list of valid choices and checking if the player's input is in that listIgnoring invalid inputs and continuing the game

Within the tutorial casino craps game pseudocode, where should you place the pseudocode that performs the task of "Get if the player won or lost" and how (in pseudocode) should this task be implemented?a.)In method play, with pseudocodemethod play()...set a local variable to won or lostb.)In Loop until Games Played = Times to Play, with pseudocodeLoop until Games Played = Times to Play...If the player won...Set "Get if the player won or lost" to wonElse if player lost...Set "Get if the player won or lost" to lostc.)In method play, with pseudocodemethod play()...return if the player won or lostd.)In Loop until Games Played = Times to Play, with pseudocodeLoop until Games Played = Times to Play...If the player won...Else if player lost...Set "Get if the player won or lost" to won or lost

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.