I am trying to make class that sets the time using three integer variables for amount of hours, minutes, and seconds, and a fourth Boolean variable to set AM or PM. I am able to get the three integer variables to work correctly, but I don't know what I am doing wrong regarding the Boolean variable not being assigned or tested correctly.
public class Time
{
private int hour;
private int minute;
private int second;
private boolean amPm;
public Time(int setHour, int setMinute, int setSecond, boolean setAmPm)
{
hour = setHour;
minute = setMinute;
second = setSecond;
amPm = setAmPm;
}
public String toString()
{
if (amPm == true)
{
String halfDay = "P.M.";
}
else
{
String halfDay = "A.M.";
}
return hour + ":" + minute + ":" + second + " " + halfDay + ".";
}
}