Answered step by step
Verified Expert Solution
Link Copied!

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 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;
image text in transcribed

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

More Books

Students also viewed these Databases questions