Question: Write a class TimeOfDay that uses the exception classes defined in the previous exercise. Give it a method setTimeTo(timeString) that changes the time if timeString
Write a class TimeOfDay that uses the exception classes defined in the previous exercise. Give it a method setTimeTo(timeString) that changes the time if timeString corresponds to a valid time of day. If not, it should throw an exception of the appropriate type.
Previous exercise.
Derive exception classes from the class you wrote in the previous exercise. Each new class should indicate a specific kind of error. For example, InvalidHourException could be used to indicate that the value entered for hour was not an integer in the range 1 to 12.
Write an exception class that is appropriate for indicating that a time entered by a user is not valid. The time will be in the format hour:minute followed by “am” or “pm.”
Step by Step Solution
3.45 Rating (158 Votes )
There are 3 Steps involved in it
public class TimeOfDay private int hour private int minute private boolean isAM Creates a new instance of TimeOfDay public TimeOfDay hour 0 minute 0 isAM false public void setTimeToString aTime throws ... View full answer
Get step-by-step solutions from verified subject matter experts
