I am trying to create a weekly calendar using 2d arrays. the calendar is also supposed to convert military time to 12hour format and my methods are not working. I am also supposed to create a method that will create an output in the format of "hour(am/pm) : description". an example is 10am : doctor
so far for my conversion method i have
/**
* Set the hour of this appointment, using a more human-friendly
* string.
* @param newHour The new hour for this appointment, using an
* am/pm designation such as "9am" or "5pm".
*/
public void setTime(String newHour)
{
String str = "";
System.out.println(newHour.length());
if (newHour.length() == 3)
{
str = newHour.substring(1, newHour.length());
System.out.println(str);
}
if (str.equalsIgnoreCase("AM"))
{
this.hour = Integer.parseInt(newHour.substring(0, 1));
}
else if (str.equalsIgnoreCase("PM"))
{
System.out.println(newHour.substring(0, 1));
this.hour = 12 + Integer.parseInt(newHour.substring(0, 1));
}
else
{
str = newHour.substring(2, newHour.length());
}
if (str.equalsIgnoreCase("PM"))
{
this.hour = 12 + (Integer.parseInt(newHour.substring(0)));
}
}
and for the formatting method i have
/**
* Get a string representation of this appointment.
* @return A human-readable representation of this appointment
* that includes the time (in am/pm format) and the description,
* such as "11am: CS 1114".
*/
@Override
public String toString()
{
if (hour < 12)
{
return hour + ":" + description;
}
else if (hour == 12)
{
return hour + ":" + description;
}
else
{
return hour + (hour - 12) + ":" + description;
}
}
any help is greatly appreciated
