Question: n this program we ask the user to enter a time in military time ( 2 4 hours ) . The program will convert and
n this program we ask the user to enter a time in military time hours The program
will convert and display the equivalent conventional time hour with AM or PM for
each entry if it is a valid military time. An error message will be printed to the console if
the entry is not a valid military time.
Think about how you would convert any military time : to : into conventional
time. Also think about what would be valid military times. To be a valid time, the data
must have a specific form. First, it should have exactly characters. Next, only digits are
allowed in the first two and last two positions, and that a colon is always used in the
middle position. Next, we need to ensure that we never have over hours or minutes.
This will require us to separate the substrings containing the hours and minutes. When
converting from military time to conventional time, we only have to worry about times
that have hours greater than and we do not need to do anything with the minutes at
all. To convert, we will need to subtract and put it back together with the colon and
the minutes, and indicate that it is PM Keep in mind that : in military time is :
AM midnight and : in military time is : PM noon
We will need to use a variety of Character class and String class methods to
validate the data and separate it in order to process it We will also use a Character
class method to allow the user to continue the program if desired.
Task:
Implement Time.java and TimeDemo.java.
Time class should validate the data and have a toString method to represent a time
instance in conventional format.
In the TimeDemo class, please implement that it asks for the input from user
iteratively and convert the input string into a conventional time for display, until user
answers Nprompt: Do you want to enter another YN
Compile, debug, and run. Test out your program using the following valid input:
a:
b:
c:
d:
e:
f:
And the following invalid input:
a:
b:
c:
d:
ee:
f:
Must be in java! Thank you in advance!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
