Question
Java eclipse Taxi Constructor: public Taxi(int theX, int theY, Direction theDir) Images: taxi.gif (alive), taxi_dead.gif (dead) Movement behavior: Taxis can only travel on streets and
Java eclipse
Taxi Constructor: public Taxi(int theX, int theY, Direction theDir) Images: taxi.gif (alive), taxi_dead.gif (dead) Movement behavior: Taxis can only travel on streets and through lights. A taxi prefers to drive straight ahead on the street if it can. If it cannot move straight ahead, it turns left if possible; if it cannot turn left, it turns right if possible; as a last resort, it turns around. Taxis stop (temporarily) for red lights; if a traffic light is immediately ahead of the taxi and the light is red, the Taxi stays still and does not move for 3 clock cycles or until the light turns green, whichever occurs first. It does not turn to avoid the light. When the light turns green, or after 3 clock cycles, whichever happens first, the taxi resumes its original direction. Taxis ignore yellow and green lights. Collision behavior: A taxi dies if it collides with a living truck, and stays dead for 5 moves.
public class Taxi extends AbstractVehicle { /** * Death Time. */ private static final int TIME = 5; /** * Constructs a taxi at the given x, y coordinates and facing a certain direction. * @param theX x-coordinate of the taxi. * @param theY y-coordinate of the taxi. * @param theDirection theDirection the taxi is facing. */ public Taxi(final int theX, final int theY, final Direction theDirection) { super(theX, theY, theDirection); myDeathTime = TIME; } public boolean canPass(final Terrain theTerrain, final Light theLight) { return theTerrain == Terrain.STREET || theLight == Light.GREEN || theLight == Light.YELLOW; } public Direction chooseDirection(final Map
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started