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

- Data fields hour, minute, and second that represent time. - A no-arg construct

ID: 3620295 • Letter: #

Question

- Data fields hour, minute, and second that represent time.
- A no-arg constructor that creates a Time object for the current time. (The values of the data fields will represent the current time.)
- A constructor that constructs a Time object with a specified elapsed time since midnight, Jan 1, 1970, in milliseconds. (The values of the data fields will represent time.)
- A constructor that constructs a Time object with the specified hour, minute, and second.
- Three get methods for the data fields hour, minute, and second, respectively.
- A method named setTime(long elapseTime) that sets a new time for the object using the elapsed time.

Draw the UML diagram for the class. Implement the class. Write a test program that creates two Time objects (using new Time() and new Time(555550000)) and display their hour, minute, and second.

(Hint: The first two constructors will extract hour, minute, and second from the elapsed time. For example, if the elapsed time is 555550 seconds, the hour is 10, the minute is 19, and the second is 9. For no-arg constructor, the current time can be obtained using System.currentTimeMills(), as shown here:

public class ShowCurrentTime {
public static void main(String[] args) {
// Obtain the total milliseconds since the midnight, Jan 1, 1970
long totalMilliseconds = System.currentTimeMillis();

// Obtain the total seconds since the midnight, Jan 1, 1970
long totalSeconds = totalMilliseconds / 1000;

// Compute the current second in the minute in the hour
int currentSecond = (int)(totalSeconds % 60);

// Obtain the total minutes
long totalMinutes = totalSeconds / 60;

// Compute the current minute in the hour
int currentMinute = (int)(totalMinutes % 60);

// Obtain the total hours
long totalHours = totalMinutes / 60;

// Compute the current hour
int currentHour = (int)(totalHours % 24);

// Display results
System.out.println("Current time is " + currentHour + ":"
+ currentMinute + ":" + currentSecond + " GMT");
}
}

Explanation / Answer

please rate - thanks if this isn't what you need message me for any changes before you rate
thanks sorry I know nothing about UMLs
----------------------------------- import java.util.*;
class TimeClass
{
private int hour,min,sec;
public TimeClass()
{long totalMilliseconds = System.currentTimeMillis();

// Obtain the total seconds since the midnight, Jan 1, 1970
long totalSeconds = totalMilliseconds / 1000;

// Compute the current second in the minute in the hour
sec = (int)(totalSeconds % 60);

// Obtain the total minutes
long totalMinutes = totalSeconds / 60;

// Compute the current minute in the hour
min = (int)(totalMinutes % 60);

// Obtain the total hours
long totalHours = totalMinutes / 60;

// Compute the current hour
hour = (int)(totalHours % 24);

}
public TimeClass(long milli)
{ // Obtain the total seconds since the midnight, Jan 1, 1970
long totalSeconds = milli/ 1000;

// Compute the current second in the minute in the hour
sec = (int)(totalSeconds % 60);

// Obtain the total minutes
long totalMinutes = totalSeconds / 60;

// Compute the current minute in the hour
min = (int)(totalMinutes % 60);

// Obtain the total hours
long totalHours = totalMinutes / 60;

// Compute the current hour
hour = (int)(totalHours % 24);

}
public int getHour()
{
return hour;
}
public int getMinute()
{
return min;
}
public int getSecond()
{
return sec;
}
public void setTime(long elapseTime)
{

// Compute the current second in the minute in the hour
sec = (int)(elapseTime % 60);

// Obtain the total minutes
long totalMinutes = elapseTime / 60;

// Compute the current minute in the hour
min = (int)(totalMinutes % 60);

// Obtain the total hours
long totalHours = totalMinutes / 60;

// Compute the current hour
hour = (int)(totalHours % 24);
}
}