Answered You can hire a professional tutor to get the answer.

QUESTION

Write a Java statement that throws a new exception with the String: File Not Found. Write a Java statement that throws a new exception with the...

  1. Write a Java statement that throws a new exception with the String: File Not Found.
  2. Write a Java statement that throws a new exception with the String: Disk drive not ready.
  3. Use a catch block to display the exception thrown in number one above.
  4. Use a catch block to display the exception thrown in number two above.
  5. Define an exception class called FileNotFoundException. The class should have a constructor with no parameters. If an exception is thrown with this zero-argument constructor, getMessage should return "File Not Found!" The class should also have a constructor with a single parameter of type String. If an exception is thrown with this constructor, then getMessage returns the value that was used as an argument to the constructor.
  6. Define an exception class called DiskDriveNotReady. The class should have a constructor with no parameters. If an exception is thrown with this zero-argument constructor, getMessage should return "Disk Drive Not Ready!" The class should also have a constructor with a single parameter of type String. If an exception is thrown with this constructor, then getMessage returns the value that was used as an argument to the constructor.
  7. What is the catch or declare rule?
  8. Write a complete Java program that prompts the user for two nonnegative integer numbers. Your program should handle bad input data.
  9. Revise the program in number 8 above to use a try/catch block to handle the IOException.
  1. Define an exception class called NegativeNumberException. The class should have a constructor with no parameters. If an exception is thrown with this zero-argument constructor, getMessage should return "Negative Number Not Allowed!" The class should also have a constructor with a single parameter of type String. If an exception is thrown with this constructor, then getMessage returns the value that was used as an argument to the constructor.
  2. Revise the program in number 9 above to throw a NegativeNumberException if the user enters a negative number.
  3. If you were going to catch an exception of type Exception, where should this catch block be placed within your code?
  4. What is the purpose of the finally block?
  5. Should an application catch objects of type Error?
  6. List five common examples of exceptions that occur.
  7. What is the purpose of the method getMessage() when used with exception handling?
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question