Part One

Implement a program that will input two times of the day, determine if they are valid times, and if the times are valid, determine which time is before the other. Here is what an example run should look like:

Input the hour and minute of the first time of day: 12 13
Input 0 if AM or 1 if PM: 1
12:13PM is a valid time.
Input the hour and minute of the second time of day: 1 42
Input 0 if AM or 1 if PM: 1
1:42PM is a valid time.
12:13PM is before 1:42PM.

User input is underlined. If a time (or input) is invalid, an appropriate message should be printed indicating why, e.g., -13 is too low for the minute value. If either time is invalid, it does not make sense to compare them. Do not worry about the user inputting non-ints.

All decisions must be done by if statements (or if/else or if/else if/else or switch statements or conditional operators). No Java class such as Date or Calendar can be used in your program. The purpose of Part One is to use conditions. Example code to print a valid time might be something like:

System.out.printf("%s:%s", hour, minute);
if (ampmInput == 0) {
System.out.print("AM");
} else {
System.out.print("PM");
}

Extra Credit: Allow the user to also input the time in 24-hour numbers, e.g., 1:42PM is equivalent to 13:42 in 24-hour time. For example, two of the prompts above could be changed to:

Input 0 if AM or 1 if PM or 2 if 24-hour:

The time should be printed out in the format that the user specifies.

Part Two

Answer the following questions and save your answers in a text file (.txt extension) in your Eclipse project. You can start editing a text file in Eclipse using:

File > New > Untitled Text File

Then do File > Save to start a dialog to save the file in your project.

1. Suppose the month of the year is stored in an int variable named month. Write an if/ else if/else statement that assigns the variable daysInMonth to the number of days in the month. If the value of month is invalid, daysInMonth should be set to 0. Do not worry about leap years. Do not include any print statements.

2. Draw a flowchart for your answer to exercise 1. This should be included in your project as a separate image file (.jpg or .png). After you move the image to your project folder, right-click on your project and select refresh.

3. Assume that x is 1 and y is 2. Show the results of the following Boolean expressions.

(x < 0) && (x < y)
(x < 0) || (x < y)
(x > 0) && (x < y)
(x > 0) || (x < y)
(x < 0) && (x > y)
(x < 0) || (x > y)
(x > 0) && (x > y)
(x > 0) || (x > y)
!(x = = y) && (y == 2)
!(!(x > 0) || !(x < y))
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.