Question: The while loop makes up to two attempts to read an integer divisible by 2 5 from input into numCents. Use multiple exception handlers to:

The while loop makes up to two attempts to read an integer divisible by 25 from input into numCents. Use multiple exception handlers to:
Catch an InputMismatchException, output "Bad input type: The TotalCents program exits", and assign attemptsLeft with 0.
2
Catch an Exception, output the message of the Exception, and subtract 1 from attemptsLeft.
End each output with a newline.
Ex: If the input is 475, then the output is:
Attempts left: 2
Valid input: 475 cents =19 quarters
Ex: If the input is B, then the output is:
Attempts left: 2
Bad input type: The Totalcents program exits
Ex: If the input is 66475, then the output is:
Attempts left: 2
Amount cannot be converted to quarters
Attempts left: 1
Valid input: 475 cents =19 quarters
numCents = scnr. nextInt ()
if (numCents %250){
throw new Exception ("Amount cannot be converted to quarters");
}
attemptsLeft =0;
 The while loop makes up to two attempts to read an

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!