Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started