hw7
Class TransitBus
java.lang.Object
|
+--hw7.Vehicle
|
+--hw7.LocatedVehicle
|
+--hw7.TransitBus
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Comparable, Locatable
- public class TransitBus
- extends LocatedVehicle
- implements java.lang.Cloneable
This class implements a TransitBus, which is a LocatedVehicle with
an integer route number.
Constructor Summary |
TransitBus(int vin,
double lat,
double lon,
int r)
Create a new TransitBus object with the given vehicle id
number, located at the given location, with the given route number. |
Method Summary |
java.lang.Object |
clone()
Create a copy of this TransitBus object. |
int |
getRoute()
Get the route number for this TransitBus. |
void |
setRoute(int r)
Set the route number for this TransitBus. |
java.lang.String |
toString()
Provide a String representation of this TransitBus. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
TransitBus
public TransitBus(int vin,
double lat,
double lon,
int r)
- Create a new TransitBus object with the given vehicle id
number, located at the given location, with the given route number.
Use the super class constructor in order to do this, using the
constructor super(...).
- 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.r
- the route number for this bus.
getRoute
public int getRoute()
- Get the route number for this TransitBus.
- Returns:
- the route number
setRoute
public void setRoute(int r)
- Set the route number for this TransitBus.
- Parameters:
r
- the new route number
toString
public java.lang.String toString()
- Provide a String representation of this TransitBus.
- Overrides:
toString
in class LocatedVehicle
- Returns:
- a String describing this TransitBus.
clone
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
- Create a copy of this TransitBus object. A shallow copy is okay
here, because the only instance variable is a primitive type.
However, some of the super class clones are a little more
complex.
- Overrides:
clone
in class LocatedVehicle
- Returns:
- a clone of this TransitBus instance
- Throws:
java.lang.CloneNotSupportedException
- but this should never happen