Dana Vrajitoru
C101/I210 Computer Programming

C101/I210 Lab 4

Date: Wednesday, February 5, 2020.
Due date: Wednesday, February 12, 2020.

Objective: To use conditionals in Java.

Ex. 1. Greeting message.

In this project, we will input a time of the day value in military format where the hour is between 0 and 23, and is separated by a ":" character from the minutes, and we will output it in the am/pm format, followed by a greeting message such as "Good morning", "Good afternoon", or "Good evening".

a. Project.

Create an Eclipse project called lab4, and inside, create a class called Greeting in a package called lab4 and containing the main method. Write your name, course, semester, and lab number at the top as a comment.

b. Declaring variables.

Declare two int variables called milHour and milMin, representing the hour and minutes value in the military format. In addition, declare a String variable called separator.

Add the line
import java.util.Scanner;
between the package and the class declarations. Then declare a Scanner variable like usual:
Scanner scan = new Scanner(System.in);

c. Input.

Output a message asking the user to enter the time in military format, using the format "HH : MM". It's important to have a space before and after the colon. Then input first the value of milHour using scan.nextInt(). Then input a value into the variable separator using scan.next(). Finally, input the value of milMin, which is also an integer.

d. Output.

For example, if the user enters
14 : 21
then the program should output
Good afternoon
2:21 pm

Ex. 2. Testing all the cases.

Test each of the 5 possible cases for the program. Copy the output in each case and add it as a comment to the file Greeting.java at the end. Use the /* ... */ style of comment for convenience.

Turn in: the file Greeting.java.

Upload it to Canvas in Assignments - Homework 4, or wait until you have completed the homework to upload both files at the same time.