Java Reference
In-Depth Information
Code 14.1
continued
An outline of the
Vehicle
class
public
Location getLocation()
{
return
location;
}
/**
* Set the current location.
* @param location Where it is. Must not be null.
* @throws NullPointerException If location is null.
*/
public
void
setLocation(Location location)
{
if
(location !=
null
){
this
.location = location;
}
else
{
throw new
NullPointerException();
}
}
/**
* @return Where this vehicle is currently headed, or
* null if it is idle.
*/
public
Location getTargetLocation()
{
return
targetLocation;
}
/**
* Set the required target location.
* @param location Where to go. Must not be null.
* @throws NullPointerException If location is null.
*/
public
void
setTargetLocation(Location location)
{
if
(location !=
null
){
targetLocation = location;
}
else
{
throw new
NullPointerException();
}
}
/**
* Clear the target location.
*/
Search WWH ::
Custom Search