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

I need to design a class named Time. The class needs to contain: -- Data fields

ID: 3539889 • Letter: I

Question

I need to design a class named Time. The class needs to contain:

-- Data fields hour, minute, and second that represent a 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 this 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.


Then, I need to Write a test program that creates two Time objects (using new Time() and new Time(555550000))

and display their hour, minute, and second.


Now, there are two of these exact questions posted on Chegg already, listed here:

1) http://www.chegg.com/homework-help/questions-and-answers/design-class-named-time-class-contains-data-fields-hour-minute-second-repsent-time-arg-con-q1443735

2) http://www.chegg.com/homework-help/questions-and-answers/design-class-named-time-class-contains-data-fields-hour-minute-second-repsent-time-arg-con-q1443735


Neither one of these actually works, so don't bother to cut-and-paste these responses. Points only awarded if the code works!


Thanks for looking!


NO SOLICIATIONS WILL BE ANSWERED OR ACKNOWLEDGED! Dont waste your time!!

Explanation / Answer

class Time

{

//data fields

private long hour;

private long minute;

private long second;

  

//no-arg constructor

public Time()

{

setTime(System.currentTimeMillis());

}

  

//elapsed time constructor

public Time(long elapsedTime)

{

setTime(elapsedTime);

}

  

//set time function

public void setTime(long elapsedTime )

{

second = (elapsedTime / 1000) % 60 ;

minute = ((elapsedTime / (1000*60)) % 60);

hour = ((elapsedTime / (1000*60*60)) % 24);

}

  

//get functions

public long getHour()

{

return hour;

}

public long getMinute()

{

return minute;

}

public long getSecond()

{

return second;

}

  

  

//TEST PROGRAM

public static void main (String args[])

{

//uses current time

Time time1 = new Time();

  

//uses elasped time 555550000 milliseconds since Jan 1, 1970

Time time2 = new Time(555550000);

  

System.out.println("First Time: " + time1.getHour() + ":" + time1.getMinute() + ":" + time1.getSecond());

System.out.println("Second Time: " + time2.getHour() + ":" + time2.getMinute() + ":"+ time2.getSecond());

}

}

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