Java Reference
In-Depth Information
Suppose that the 11 methods to implement the 11 operations are as follows (we also
specify the headings of the methods):
1. setTime sets the time to the time specified by the user. The method
heading is:
public void setTime( int hours, int minutes, int seconds)
2. getHours returns the hours. The method heading is:
public int getHours()
3. getMinutes returns the minutes. The method heading is:
public int getMinutes()
4. getSeconds returns the seconds. The method heading is:
public int getSeconds()
5. printTime prints the time in the form hh:mm:ss . The method heading
is:
public void printTime()
6. incrementHours increments the time by one hour. The method heading
is:
public void incrementHours()
7. incrementMinutes increments the time by one minute. The method
heading is:
public void incrementMinutes()
8. incrementSeconds increments the time by one second. The method
heading is:
public void incrementSeconds()
9. equals compares two times to determine whether they are equal. The
method heading is:
public boolean equals(Clock otherClock)
10. makeCopy copies the time of one Clock object into another Clock
object. The method heading is:
public void makeCopy(Clock otherClock)
11. getCopy returns a copy of the time. A copy of the object's time is
created and a reference to the copy is returned. The method heading is:
public Clock getCopy()
The objective of the method setTime is to set the values of the instance variables. In
other words, it changes the values of the instance variables. Such methods are called
mutator methods. On the other hand, the method getHours only accesses the value of an
instance variable; that is, it does not change the value of the instance variable. Such
methods are called accessor methods. These methods are described in detail later in this
chapter.
Search WWH ::




Custom Search