Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a method call to a constructor,java
    primarykey
    data
    text
    <p>Assignment: Time class:</p> <p>give it 3 private data members for hour, minute, and second. Use type long or int.</p> <p>If you use int you must cast inside the ctors.</p> <p>add a no-arg ctor that uses code like that in Listing 2.6 on p38 to assign values to hour, minute, and second from the current time.</p> <p>add another ctor that will take a single long parameter named elapseTime (better would be elapsedTime), a number for milliseconds since the Unix epoch date. this second ctor will also use code as per Listing 2.6 to set the data members for that elapsed time since the epoch.</p> <p>add a getter for each data member. Each getter will require only a single statement.</p> <p>Getters are needed because the data members are private.</p> <p>add a toString method that returns the hours, minutes, and seconds for a Time object.</p> <p>here is my class Time() code, my setTime() code represents the book reference mentioned above.</p> <p>package chapter_10;</p> <pre><code>public class Time { private long hour; private long minute; private long second; public Time() { } public void setTime(long elapsedTime){ long millisecond = System.currentTimeMillis(); second = millisecond / 1000; minute = second / 60; hour = minute /60; //equate for current time. second = second %60; minute = minute %60; hour = hour %24; } public long getHour() { return hour; } public long getMinute() { return minute; } public long getSecond() { return second; } public String toString(){ return getHour() + ":" + getMinute() + ":" + getSecond(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload