Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Vehicle Descriptions: Truck Constructor: public Truck(int theX, int theY, Direction theDir) Images: truck.gif (alive), truck_dead.gif (dead) Movement behavior: Trucks travel only on streets and through

Vehicle Descriptions:

Truck Constructor:

public Truck(int theX, int theY, Direction theDir) Images: truck.gif (alive), truck_dead.gif (dead) Movement behavior: Trucks travel only on streets and through lights and crosswalks. Trucks randomly select to go straight, turn left, or turn right. As a last resort, if none of these three directions is legal (all not streets, lights, or crosswalks), the truck turns around. Trucks drive through all traffic lights without stopping! Trucks stop for red crosswalk lights, but drive through yellow or green crosswalk lights without stopping. Collision behavior: A truck survives a collision with anything, living or dead.

Car Constructor:

public Car(int theX, int theY, Direction theDir) Images: car.gif (alive), car_dead.gif (dead) Movement behavior: Cars only travel on streets and through traffic lights and crosswalks. Cars prefer to drive straight ahead on streets, traffic lights, and crosswalks. If a Car 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. Cars stop for red and yellow traffic lights; if a traffic light is immediately ahead of the car and the light is yellow or red, the car stays still and does not move. It does not turn to avoid the light. When the light turns green, the car resumes its original direction. Cars stop for red and yellow crosswalk lights, but drive through green crosswalk lights without stopping. Collision behavior: A car dies if it collides with a living truck, and stays dead for 10 moves.

All-Terrain Vehicle (ATV) Constructor:

public Atv(int theX, int theY, Direction theDir) Images: atv.gif (alive), atv_dead.gif (dead) Movement behavior: ATVs can travel on any terrain except walls. They randomly select to go straight, turn left, or turn right. ATVs only reverse direction if they have no other option. ATVs drive through all traffic lights and crosswalk lights without stopping! Collision behavior: An ATV dies if it collides with a living truck or car and stays dead for 20 moves. 3 of 10 Bicycle Constructor: public Bicycle(int theX, int theY, Direction theDir) Images: bicycle.gif (alive), bicycle_dead.gif (dead) Movement behavior: Bicycles can travel on streets and through lights and crosswalk lights, but they prefer to travel on trails. If the terrain in front of a bicycle is a trail, the bicycle always goes straight ahead in the direction it is facing. Trails are guaranteed to be straight (horizontal or vertical) lines that end at streets, and you are guaranteed that a bicycle will never start on a trail facing terrain it cannot traverse. If a bicycle is not facing a trail, but there is a trail either to the left or to the right of the bicycles current direction, then the bicycle turns to face the trail and moves in that direction. You may assume that the map is laid out so that only one trail will neighbor a bicycle at any given time. If there is no trail straight ahead, to the left, or to the right, the bicycle prefers to move straight ahead on a street (or light or crosswalk light) if it can. If it cannot move straight ahead, it turns right if possible; if it cannot turn right, it turns left if possible. As a last resort, if none of these three directions is legal (all not streets or lights or crosswalk lights), the bicycle turns around. Bicycles stop for yellow and red lights; if a traffic light or crosswalk light is immediately ahead of the bicycle and the light is not green, the bicycle stays still and does not move unless a trail is to the left or right. If a bicycle is facing a red or yellow light and there is a trail to the left or right, the bicycle will turn to face the trail. Collision behavior: A bicycle dies if it collides with a living truck, car, or ATV. It stays dead for 30 moves.

Human Constructor:

public Human(int theX, int theY, Direction theDir) Images: human.gif (alive), human_dead.gif (dead) Movement behavior: Humans move in a random direction (straight, left, right, or reverse), always on grass or crosswalks. Human never reverse direction unless there is no other option. If a human is next to a crosswalk it will always choose to turn to face in the direction of the crosswalk. (The map of terrain will never contain crosswalks that are so close together that a human might be adjacent to more than one at the same time.) Humans do not travel through crosswalks when the crosswalk light is green. If a human is facing a green crosswalk, it will wait until the light changes to yellow and then cross through the crosswalk. The human will not turn to avoid the crosswalk. Humans travel through crosswalks when the crosswalk light is yellow or red. Collision behavior: A human dies if it collides with any living vehicle except another human, and stays dead for 40 moves.

NOTE:

Also need to write a JUint Test Case for Truck Class.

No helper methods are allowed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How are costs and expenses different?

Answered: 1 week ago