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

The while loop makes up to two attempts to read an integer divisible by 10 from input into numCents. Use multiple exception
handlers to:
Catch an InputMismatchException, output "Unexpected input: The TotalCents program terminates", and assign triesLeft
with 0.
Catch an Exception, output the message of the Exception, and subtract 1 from triesLeft.
End each output with a newline.
Ex: If the input is 440, then the output is:
Tries left: 2
Valid input: 440 cents =44 dimes
Ex: If the input is Q, then the output is:
Tries left: 2
Unexpected input: The TotalCents program terminates
Ex: If the input is 92440, then the output is:
Tries left: 2
Amount cannot be converted to dimes
Tries left: 1
Valid input: 440 cents =44 dimes
import java.util.Scanner;
import java.util. InputMismatchException;
public class Totalcents {
public static void main(String[] args)(
Scanner scnr = new Scanner(
System.in);
int numCents;
int triesLeft =2;
while (triesLeft >0){
System.out.println("Tries left: "+ triesLeft);
try {
numCents = scnr.nextint ();
if (numCents 810,0){
throw new Exception("Amount cannot be converted to dimes");
}
triesLeft =0;
System.out.print ("Valid input: ");
System.out.println(numCents +" cents ="+(numCents /10)+" dimes");
}
/* Your code goes here */
}
}
}
 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!