Java Reference
In-Depth Information
public void
setTime(
int
hours,
int
minutes,
int
seconds)
{
if
(0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if
(0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if
(0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
//Method to return the hours
//Postcondition: the value of hr is returned
public int
getHours()
{
return
hr;
}
//Method to return the minutes
//Postcondition: the value of min is returned
public int
getMinutes()
{
return
min;
}
//Method to return the seconds
//Postcondition: the value of sec is returned
public int
getSeconds()
{
return
sec;
}
//Method to print the time
//Postcondition: Time is printed in the form hh:mm:ss
public void
printTime()
{
if
(hr < 10)
System.out.print("0");
System.out.print(hr + ":");
if
(min < 10)
System.out.print("0");
System.out.print(min + ":");
Search WWH ::
Custom Search