Problem 1:

Write an exception class NoDigitsException.

  • This exception should include the message "No digits found"
  • Whenever an exception of this type is created, add an entry to a log file"NoDigitsException log.txt"
    • time/date stamp (look up the Javadoc for Date class)
    • The string that was entered to cause the exception

Note: use the append method of file operations. Explanation and example can be found at https://docs.oracle.com/javase/tutorial/essential/io/file.html

Problem 2:

In keeping with robust programming principles, you need the ability to ask the user for a number and handle anything they type into the keyboard without crashing your program. Write a support class Keyboard that include methods getInt() and getDouble(). Polymorph them with versions that accept a String parameter to provide as a prompt.

These methods do the following:

  • Print the prompt (for the prompt versions), accept keyboard String input.
  • If no digits occur in the input, throw a NoDigitsException.
  • Remove all characters except for digits and (for the doubles) the first decimal point.
  • (for the doubles) add a 0 if no other digits occur after the decimal.
  • Parse the remaining String to int/double and return the result.

Problem 3:

Write a test class to verify your Keyboard class operates correctly by asking the user for ints and doubles using both the prompted and non-prompted versions (provide a prompt as needed before calling the method).

  • catch any NoDigitsException and print the exception message.
  • continue to ask for numbers until two NoDigitsExceptions have been thrown. Exit when the second exception is thrown.

Construct and submit a UML diagram of these classes.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.