|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--hw7.Vehicle
This class provides an implementation for a basic vehicle that has a vehicle identification number and the ability to sort based on that number. As implemented here, the class is immutable. That is, once an object is created, the vin cannot be changed. However, the vin is declared to be protected, rather than private, so if you need a mutable Vehicle (as search key for a Map for example) you can extend this class and define a setVIN method there.
Field Summary | |
protected int |
vin
the vehicle identification number |
Constructor Summary | |
Vehicle(int id)
Create a new Vehicle with the given vehicle identification number. |
Method Summary | |
java.lang.Object |
clone()
Create a copy of this Vehicle object. |
int |
compareTo(java.lang.Object o)
Compares this object with the specified object for order, based on the vehicle identification number. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one, based on a comparison of vehicle id numbers. |
int |
getVIN()
Return the vehicle id number for this Vehicle. |
int |
hashCode()
Returns a hash code value for this Vehicle, namely the vehicle identification number. |
static void |
main(java.lang.String[] arg)
Test harness for this class. |
java.lang.String |
toString()
Provide a String representation of this Vehicle. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int vin
Constructor Detail |
public Vehicle(int id)
vin
- the vehicle identification numberMethod Detail |
public int getVIN()
public java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
o
- the other Vehicle objectpublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the other Vehicle objectpublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- but this should never happenpublic static void main(java.lang.String[] arg)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |