hw6
Class LocatedVehicle

java.lang.Object
  |
  +--hw6.Vehicle
        |
        +--hw6.LocatedVehicle
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, Locatable
Direct Known Subclasses:
TransitBus

public class LocatedVehicle
extends Vehicle
implements Locatable, java.lang.Cloneable

This class implements the ability to give a Vehicle a Location.


Field Summary
 
Fields inherited from class hw6.Vehicle
vin
 
Constructor Summary
LocatedVehicle(int vin, double lat, double lon)
          Create a new LocatedVehicle object with the given vehicle id number and located at the given location.
 
Method Summary
 java.lang.Object clone()
          Create a copy of this LocatedVehicle object.
 double distanceTo(hw6.Locatable other)
          Calculate the distance to another Locatable object
 hw6.Location getLocation()
          Return a reference to a copy of the Location object describing our current position.
 void setLocation(double lat, double lon)
          Set the values of our current Location by copying them from the arguments provided.
 void setLocation(hw6.Location loc)
          Set the values of our current Location by copying them from the given Location object.
 java.lang.String toString()
          Provide a String representation of this LocatedVehicle.
 
Methods inherited from class hw6.Vehicle
compareTo, equals, getVIN, hashCode, main
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocatedVehicle

public LocatedVehicle(int vin,
                      double lat,
                      double lon)
Create a new LocatedVehicle object with the given vehicle id number and located at the given location.

Parameters:
vin - the vehicle id number
lat - the latitude where this Vehicle is located. Must satisfy the constraints defined by the Location class.
lon - the longitude where this Vehicle is located. Must satisfy the constraints defined by the Location class.
Method Detail

getLocation

public hw6.Location getLocation()
Return a reference to a copy of the Location object describing our current position.

Specified by:
getLocation in interface Locatable
Returns:
a copy of the Location object for this object

setLocation

public void setLocation(hw6.Location loc)
Set the values of our current Location by copying them from the given Location object.

Specified by:
setLocation in interface Locatable
Parameters:
loc - the Location to copy from

setLocation

public void setLocation(double lat,
                        double lon)
Set the values of our current Location by copying them from the arguments provided. The arguments must satisfy the constraints imposed by the Location class.

Specified by:
setLocation in interface Locatable
Parameters:
lat - the new latitude value
lon - the new longitude value

distanceTo

public double distanceTo(hw6.Locatable other)
Calculate the distance to another Locatable object

Specified by:
distanceTo in interface Locatable
Parameters:
other - the other Location
Returns:
the distance in meters to the other object

toString

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

Overrides:
toString in class Vehicle
Returns:
a String describing this LocatedVehicle

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Create a copy of this LocatedVehicle object. We need to do a little patching after the clone, because we don't want to return a reference to our own Location object, but rather to a clone of it.

Overrides:
clone in class Vehicle
Returns:
a clone of this LocatedVehicle instance
Throws:
java.lang.CloneNotSupportedException - but this should never happen