hw7
Class LocatedVehicle
java.lang.Object
|
+--hw7.Vehicle
|
+--hw7.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.
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(Locatable other)
Calculate the distance to another Locatable object |
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(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 java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
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 numberlat
- 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.
getLocation
public 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(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 valuelon
- the new longitude value
distanceTo
public double distanceTo(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