Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

What is the formula to calculate the mth Fibonacci number?

Answered: 1 week ago