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 from input into numCents. Use multiple exception handlers to:
Catch an InputMismatchException, output "Bad input type: The TotalCents program exits", and assign attemptsLeft with
Catch an Exception, output the message of the Exception, and subtract from attemptsLeft.
End each output with a newline.
Ex: If the input is then the output is:
Attempts left:
Valid input: cents quarters
Ex: If the input is then the output is:
Attempts left:
Bad input type: The Totalcents program exits
Ex: If the input is then the output is:
Attempts left:
Amount cannot be converted to quarters
Attempts left:
Valid input: cents quarters
numCents scnr nextInt
if numCents
throw new Exception Amount cannot be converted to quarters";
attemptsLeft ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
