Class Vehicle

java.lang.Object
  |
  +--Vehicle
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
LocatedVehicle

public class Vehicle
extends java.lang.Object
implements java.lang.Comparable

This class provides an implementation for a basic vehicle that has a vehicle identification number and the ability to sort based on that number.


Constructor Summary
Vehicle(int id)
          Create a new Vehicle with the given vehicle identification number.
 
Method Summary
 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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vehicle

public Vehicle(int id)
Create a new Vehicle with the given vehicle identification number.

Method Detail

getVIN

public int getVIN()
Return the vehicle id number for this Vehicle.

Returns:
the vehicle id number

toString

public java.lang.String toString()
Provide a String representation of this Vehicle.

Overrides:
toString in class java.lang.Object
Returns:
a String describing this Vehicle

compareTo

public int compareTo(java.lang.Object o)
Compares this object with the specified object for order, based on the vehicle identification number.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the other Vehicle object
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one, based on a comparison of vehicle id numbers. This is implemented to remain consistent with compareTo.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the other Vehicle object
Returns:
true if equal, false if not

hashCode

public int hashCode()
Returns a hash code value for this Vehicle, namely the vehicle identification number. This is implemented to remain consistent with equals(), because if two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object

main

public static void main(java.lang.String[] arg)
Test harness for this class.