This is the out put:
The time is 8:3:8AM The time is 8:3:8
This is the desired output:
The time is 08:03:08 AM The time is 08:03:08
So i need to convert this into the desired output where if it's 8:03:04 where 8 hours and 3 minutes and 4 seconds should be displyed like above. with zeros infront of the single digits
package Assignment2;
class clock{
public static void main(String[] args) {
clock timer = new clock();
timer.setTime(8,02,59);
timer.incTime(9);
//timer.incTime(60);
timer.display12hr();
timer.display24hr();
}
private int minutes, hours, seconds;
clock()
{
minutes = 0;
hours = 0;
seconds = 0;
}
clock(int x, int y, int z)
{
hours = x;
minutes = y;
seconds = z;
}
void setTime(int x, int y, int z)
{
hours = x;
minutes = y;
seconds = z;
}
void incTime(int y)
{
if (seconds + y > 59)
{
seconds = (seconds + y) - 60;
minutes++;
}
else
seconds += y;
}
void display12hr()
{
if (hours > 12)
{
System.out.println("The time is " + (hours - 12) + ":" + minutes + ":" + seconds
+ "PM");
}
else
{
System.out.println("The time is " + (hours) + ":" + minutes + ":" + seconds +"AM");
}
}
void display24hr()
{
System.out.println("The time is " + (hours) + ":" + minutes + ":" + seconds);
}
}