Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program , Java classes to write a method called advanceHrs to advan

ID: 3767451 • Letter: W

Question

Write a java program , Java classes to write a method called advanceHrs to advance the time by one hour.

A method called advanceMins to advance the time by one minute. This method should use in its definition the method advanceHrs.

A method called advanceSecs to advance the time by one second. This method should overwrite the method increment available in class Time and make use of the previous 2 methods in its definition. After you write it, remove the method increment from class Time.

Write an alternate definition for method getCopy (use the alternate constructor)

Explanation / Answer

//TimeOfDay program

public class TimeOfDay
{

private int hour;
private int minute;
private int second;


/**
* Constructor for objects of class TimeOfDay
*/
public TimeOfDay( int h, int m, int s)
{
setHr( h );
setMin( m );
setSec(s);
String time = "17:46:35";
String [] values = time.split(":");

}

public TimeOfDay()
{

}


  

public void setHr (int h )
{
if (0 <= h && h < 23 )
hour = h;
else
hour = 0;
}

public void setMin (int m)
{
if (0 <= m && m < 59)
minute = m;
else
minute = 0;
}

public void setSec (int s)
{
if (0 <= s && s < 59)
second = s;
else
second = 0;
}
public void advanceHrs()
{
hour++;

if ( hour > 23 )
hour = 0;
}

public void advanceMins()
{
minute++;

if ( minute > 59 )
{
minute = 0;
addHour(); //increment hour
}
}
public void advanceSecs()
{
second++;

if ( second> 59 )
{
second = 0;
addSecond(); //increment second
}
}

public int printCurrentTime() {
System.out.printf("%02d:%02d:%02d%n", hour, minute,second);
return hour * 60 + minute + second;
}

  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote