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

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 non-negative number bet 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();
}
catch(InputMismatchcatchion ex){
System.out.println("Not a valid bet. Please enter a number for your bet.");
// Clear out input to remove
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();
playMultipleGames(number,betAmount);
}
catch(InputMismatchcatchion ex){
System.out.println("Not a valid bet. Please enter a number for your bet.");
// Clear out input to remove
input.nextLine();
}
}
System.out.println(); // Add blank line in output
c.)
// 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 <0)
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 for your bet.");
// Clear out input to remove
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 <0){
try {
System.out.print("Pass Line Bet : ");
betAmount = input.nextInt();
if (betAmount >=0)
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 for your bet.");
// Clear out input to remove
input.nextLine();
}
}
System.out.println(); // Add blank line in output

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!