Question: Exercise 2 Description For this lab you will write a Java program to prompt the user to enter a time in HH:MM AM/PM format. Your
Exercise 2 Description
For this lab you will write a Java program to prompt the user to enter a time in HH:MM AM/PM format. Your program will break this string up into hours, minutes and AM or PM and then convert this to an integer in military time. Create a new Java program named Lab04b.java for this problem.
Exercise 2 Sample Output
This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter a time in HH:MM AM/PM format: 2:34 PM Time in military time is: 1434 A second run of this code might produce the following output: Enter a time in HH:MM AM/PM format: 1:46 AM Time in military time is: 146 NOTE: For this exercise you should assume that the input will be properly formatted with an hour between 1 and 12, then a colon (':'), then minutes between 00 and 59, then a space and either the token 'AM' or 'PM'. Your code should take the line from the user as a string and turn it into an integer value. The table below shows standard time values and their corresponding military time values. Note that for this assignment you do not need to format your output to include leadings zeroes for times less than 1000.
| Regular Time | Military Time | Regular Time | Military Time |
| Midnight | 0000 | Noon | 1200 |
| 1:00 AM | 0100 | 1:00 PM | 1300 |
| 2:00 AM | 0200 | 2:00 PM | 1400 |
| 3:00 AM | 0300 | 3:00 PM | 1500 |
| 4:00 AM | 0400 | 4:00 PM | 1600 |
| 5:00 AM | 0500 | 5:00 PM | 1700 |
| 6:00 AM | 0600 | 6:00 PM | 1800 |
| 7:00 AM | 0700 | 7:00 PM | 1900 |
| 8:00 AM | 0800 | 8:00 PM | 2000 |
| 9:00 AM | 0900 | 9:00 PM | 2100 |
| 10:00 AM | 1000 | 10:00 PM | 2200 |
| 11:00 AM | 1100 | 11:00 PM | 2300 |
NOTE 2: For this assignment you will need to use the Integer.parseInt() method. The code below shows an example of how to use this method to convert a String into an integer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
