Class Watch

java.lang.Object
  extended by Watch

public class Watch
extends Object

This class represents a watch. A watch has the time, a colour and an owner. Each watch also has a unique id (all watches have a different id).


Field Summary
static int BLUE
          The colour blue.
static int RED
          The colour red.
static int WHITE
          The colour white.
 
Constructor Summary
Watch(int colour, String owner)
          Creates a watch with the given colour and owner and the current time.
Watch(String owner)
          Creates a white watch with the current time and the given owner.
 
Method Summary
 boolean equals(Object object)
          Tests if this watch is equal to the given object.
 int getColour()
          Returns the colour of this watch.
 int getId()
          Returns the id of this watch.
 String getOwner()
          Returns the owner of this watch.
 long getTime()
          Returns the time of this watch (the number of milliseconds since January 1, 1970).
 void setOwner(String owner)
          Sets the owner of this watch to the given owner.
 String toString()
          Returns a string representation of this watch.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RED

public static final int RED
The colour red.

See Also:
Constant Field Values

WHITE

public static final int WHITE
The colour white.

See Also:
Constant Field Values

BLUE

public static final int BLUE
The colour blue.

See Also:
Constant Field Values
Constructor Detail

Watch

public Watch(int colour,
             String owner)
Creates a watch with the given colour and owner and the current time.

Parameters:
colour - the colour of the watch.
owner - the owner of the watch.
Precondition:
colour == Watch.RED or colour == Watch.WHITE or colour == Watch.BLUE

Watch

public Watch(String owner)
Creates a white watch with the current time and the given owner.

Parameters:
owner - the owner of the watch.
Method Detail

getId

public int getId()
Returns the id of this watch.

Returns:
the id of this watch.

getTime

public long getTime()
Returns the time of this watch (the number of milliseconds since January 1, 1970).

Returns:
the time of this watch.

getColour

public int getColour()
Returns the colour of this watch.

Returns:
the colour of this watch.

getOwner

public String getOwner()
Returns the owner of this watch.

Returns:
the owner of this watch.

setOwner

public void setOwner(String owner)
Sets the owner of this watch to the given owner.

Parameters:
owner - the owner to set

equals

public boolean equals(Object object)
Tests if this watch is equal to the given object. Two watches are considered equal if they have the same owner and the same colour.

Overrides:
equals in class Object
Parameters:
object - an object.
Returns:
true if this watch is equal to the given object, false otherwise.

toString

public String toString()
Returns a string representation of this watch. The representation consists of the string "A watch owned by " followed by the owner of this watch, followed by the string " with id " followed by the id of this watch.

Overrides:
toString in class Object
Returns:
a string representation of this watch.