|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Driver
public class Driver
This class represents a car driver. A driver has a name, a preferred driving speed, and knows which car he's driving. A driver can be human or computer. This class was originally written for the third programming assignment in CS 302 at UW-Madison in Spring 2009 by the current author.
Field Summary | |
---|---|
static int |
GO_LEFT
Indicates that the driver chose to go one lane to the left. |
static int |
GO_RIGHT
Indicates that the driver chose to go one lane to the right. |
static int |
STAY
Indicates that the driver chose to stay in the current lane. |
Constructor Summary | |
---|---|
Driver(java.lang.String name,
double preferredVelocity,
boolean isHuman)
Creates a new driver with a specified name and with a driving speed preference. |
Method Summary | |
---|---|
boolean |
canAct()
Indicates whether a driver is currently ready to make a decision. |
void |
enterCar(Car car)
Makes the driver enter a car. |
Car |
getDrivenCar()
Returns a reference to the car this driver is driving (null if none) |
java.lang.String |
getName()
Returns the driver's name |
double |
getPreferredVelocity()
Returns this driver's preferred driving speed. |
boolean |
isHuman()
Returnes whether this driver is human. |
int |
makeDecision(double velocityOfCarAhead,
double distanceFromCarAhead,
double velocityOfCarBehind,
double distanceFromCarBehind,
double velocityOfCarAheadLeft,
double distanceFromCarAheadLeft,
double velocityOfCarBehindLeft,
double distanceFromCarBehindLeft,
double velocityOfCarAheadRight,
double distanceFromCarAheadRight,
double velocityOfCarBehindRight,
double distanceFromCarBehindRight,
double tickLength)
The driver decides how to change the velocity of the car he is driving based on the information about nearby cars. |
void |
setCanAct(boolean canAct)
Updates whether this driver is ready to make a decision. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int STAY
public static final int GO_LEFT
public static final int GO_RIGHT
Constructor Detail |
---|
public Driver(java.lang.String name, double preferredVelocity, boolean isHuman)
name
- The driver's namepreferredVelocity
- How fast the driver prefers to goisHuman
- Whether this driver is humanMethod Detail |
---|
public java.lang.String getName()
public boolean isHuman()
public Car getDrivenCar()
public double getPreferredVelocity()
public void enterCar(Car car)
car
- The car this driver is enteringpublic boolean canAct()
public void setCanAct(boolean canAct)
canAct
- true if the driver should make a decision,
false otherwise.public int makeDecision(double velocityOfCarAhead, double distanceFromCarAhead, double velocityOfCarBehind, double distanceFromCarBehind, double velocityOfCarAheadLeft, double distanceFromCarAheadLeft, double velocityOfCarBehindLeft, double distanceFromCarBehindLeft, double velocityOfCarAheadRight, double distanceFromCarAheadRight, double velocityOfCarBehindRight, double distanceFromCarBehindRight, double tickLength)
velocityOfCarAhead
- Velocity of the car immediately ahead of the driver's car.distanceFromCarAhead
- Distance of the rear of the car immediately ahead from the
front of the driver's car.velocityOfCarBehind
- Velocity of the car immediately behind the driver's car.distanceFromCarBehind
- Distance of the front of the car immediately behind the
driver's car from the rear of the driver's car.velocityOfCarAheadLeft
- Velocity of the car immediately ahead of the driver's car in
the lane that's one to the left from the driver's lane.distanceFromCarAheadLeft
- Distance of the rear of the car immediately ahead of the driver's
car in the lane that's one to the left
from the front of the driver's car. This could be negative.velocityOfCarBehindLeft
- Velocity of the car immediately behind the driver's car in
the lane that's one to the left from the driver's lane.distanceFromCarBehindLeft
- Distance of the front of the car immediately behind the driver's
car in the lane that's one to the left from the rear of the driver's car.
This could be negative.velocityOfCarAheadRight
- Velocity of the car immediately ahead of the driver's car in
the lane that's one to the right from the driver's lane.distanceFromCarAheadRight
- Distance of the rear of the car immediately ahead of the driver's
car in the lane that's one to the right
from the front of the driver's car. This could be negative.velocityOfCarBehindRight
- Velocity of the car immediately behind the driver's car in
the lane that's one to the right from the driver's lane.distanceFromCarBehindRight
- Distance of the front of the car immediately behind the driver's
car in the lane that's one to the right from the rear of the driver's car.
This could be negative.tickLength
- The tick length for the game.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |