Sorry, I'm not trying to intimidate you, but I do want you to think.
Ok, so first you have your if statement which checks to see if the time is valid:
if(this.validate())
{
// we have a valid time, do stuff in here
}
else
{
// invalid time
System.out.println("invalid time");
}
Now that you have a valid time, we want to create a local temporary variable we can modify
without changing hh of the object. We also want a string to hold if we're in the morning or afternoon. For the sake of simplicity, let's assume it's am.
int temporaryHH = hh;
String period = "am"; // this is an assumption
After assuming it's am, we need to validate that assumption. How do we know if it's am? If temporaryHH is before noon (smaller than 12). Otherwise, it's pm. If it's pm, temporaryHH needs to be decreased by 12.
if(temporaryHH >= 12)
{
// pm
period = "pm";
temporaryHH = temporaryHH - 12;
}
The last thing to check is if temporaryHH is 0. What does it mean to be 0 am or 0 pm? That's the equivalent of 12 am or 12 pm. To see if you understand this, I'd like you to see if you can figure out how to accomplish this using the above code (remember to operate on temporaryHH, not hh).
Your final code should look something like this:
if(this.validate())
{
// we have a valid time
int temporaryHH = hh;
String period = "am"; // assume we're am
if(temporaryHH >= 12)
{
// actually in pm
period = "pm";
temporaryHH = temporaryHH - 12;
}
// TODO: what code should go here to fix if temporaryHH is 0?
// print out the valid time
System.out.println("Your time is: "+ temporaryHH +":"+ mm +":"+ ss + period);
}
else
{
// invalid time
System.out.println("invalid time");
}
If you use brackets like I did (indent in on each open bracket, indent out on each close bracket) you can easily tell if you're missing a bracket, as well as see what code belongs to which condition.