Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 7 int number; boolean done = false; do { try { System.out.print(\"Enter

ID: 3823618 • Letter: Q

Question

Question 7

int number;
boolean done = false;

do                                            
{
    try                                      
    {
        System.out.print("Enter an integer: ");        
        number = console.nextInt();           
        System.out.println();                 
        done = true;                          
        System.out.println("number = " + number);          
     }
     catch (InputMismatchException imeRef)     
     {
         str = console.next();                 
         System.out.println("Exception "
                           + imeRef.toString()
                           + " " + str);       
     }
}
while (!done);

How many times will the code in the try block in the accompanying figure execute?

Until the user specifies that he/she wants to quit the program

Until the user inputs a valid integer

If there is an exception thrown, it will execute just once because the program will terminate at that point.

Zero times; the program will terminate before it reaches the try block.

1 points   

Question 8

How many constructors does the class Exception have?

zero

one

two

three

1 points   

Question 9

Which of the following methods prints a list of the methods that were called before the exception was thrown?

getMessage()

printCalledMethods()

printStackTrace()

traceMethodStack()

1 points   

Question 10

Which of the following statements is NOT true about creating your own exceptions?

Typically, constructors are the only methods that you include when you define your own exception class.

The exception class that you define extends either the class Throwable or one of its subclasses.

If you have created an exception class, you can define other exception classes by extending the definition of the exception class you created.

You must throw your own exceptions using the throw statement.

1 points   

Question 11

Which of the following is NOT a method of the class Throwable?

getMessage

throwMessage

printStackTrace

toString

1 points   

Question 12

import java.util.*;
public class ExceptionExample1
{
    static Scanner console = new Scanner(System.in);

    public static void main(String[] args)
    {
        int dividend, divisor, quotient;

        try
        {
            System.out.print("Enter dividend: ");
            dividend = console.nextInt();
            System.out.println();
            System.out.print("Enter divisor: ");
            divisor = console.nextInt();
            System.out.println();
            quotient = dividend / divisor;
            System.out.println("quotient = " + quotient);
      }
      catch (ArithmeticException aeRef)
      {
            System.out.println("Exception" + aeRef.toString());
      }
      catch (InputMismatchException imeRef)
      {
            System.out.println("Exception "  
                             + imeRef.toString());
        }
        catch( IOException ioeRef)
        {
           System.out.println("Exception "
                         + ioeRef.toString());
        }
    }
}

Which of the following will cause the first exception to occur in the code in the accompanying figure?

If the divisor is zero

If the dividend is zero

If the quotient is zero

This code will not compile, so an exception cannot be triggered.

Until the user specifies that he/she wants to quit the program

Until the user inputs a valid integer

If there is an exception thrown, it will execute just once because the program will terminate at that point.

Zero times; the program will terminate before it reaches the try block.

Explanation / Answer

7) Until the user inputs a valid integer . [It will keep on going into while loop until theer is no InputMismatch]

8) Two, Exception() and Exception(message)

9)printStackTrace
() . [It will print the stack trace i.e all the function during the runtime stack]

10) The exception class that you define extends either the class Throwable or one of its subclasses.
we extend the class exception and not throwable
11) throwMessage does NOT belong to Throwable

12)

If the divisor is zero

Thanks, let me know if there is any concern.

If the divisor is zero

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote