Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to complete a program that prompts the user to enter time in 12-hour notation and outputs the time in 24-hour notation. Your

Your task is to complete a program that prompts the user to enter time in 12-hour notation and outputs the time in 24-hour notation.

Your program MUST define four exception classes: InvalidHrException (for invalid hours), InvalidMinException (for invalid minutes), InvalidSecException (for invalid seconds), InvalidPrdException (for invalid period). If the user enters an invalid value for hours, then the program should throw and catch an InvalidHrException object. Similar conventions for the values of minutes, seconds and period (AM or PM).

In the class Driver, you must define five methods: getHours, getMinutes, getSeconds, getPeriod and print24HourTime.

Hints:

There is no need to declare any exception objects in main. The exception objects should be thrown/handled in other method, such as getHours, getMinutes,

Methods getHours, getMinutes, getSeconds and getPeriod must continually ask the user to enter data until valid data is entered.

The valid range for seconds and minutes is 0 to 59; The valid range for hours is 1 to 12.

12:xx:xx AM should correspond to 00:xx:xx in 24-hour notation, i.e., 12:20:30 AM corresponds to 00:20:30;

12:xx:xx PM should correspond to 12:xx:xx in 24-hour notation, i.e., 12:20:30 PM corresponds to 12:20:30;

Driver Class:

package Time;

import java.io.*; import java.util.*;

public class Driver { static Scanner console = new Scanner(System.in);

public static void main(String[] args) { int hours; int minutes; int seconds; String str; hours = getHours(); minutes = getMinutes(); seconds = getSeconds(); str = getPeriod(); System.out.println(); System.out.print("24 hour clock time: "); print24HourTime(hours, minutes, seconds, str); }//end of main

//Define the getHours, getMinutes, getSeconds, //getPeriod as well as print24HourTime. }//end of class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the drawback of choosing Canary compile time over runtime

Answered: 1 week ago