Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java code for below instruction: public Car(Grid grid, int speed, int xLoc, int yLoc, int direction) A constructor for Car, The direction parameter

Write a java code for below instruction:

public Car(Grid grid, int speed, int xLoc, int yLoc, int direction)

A constructor for Car, The direction parameter sets the direction of the car: 0 for right-up and 1 for left-down. Car checks that the speed is between 3 and 8, inclusive and throws an exception otherwise. You may assume that the location given is one of the road elements.

public String getDirectionString()

A getter method for the boat's direction, returned as a String for convenience.

public int getDirection()

A getter method for the boat's direction as the stored integer.

public void move()

Car's implementation of move (see below).

public String toString()

An override of the toString method that returns a String version of the Car data (including the Vehicle instance).

Implementations of the move() method

Car: Let the car's speed be s. In each call to move(), the car moves s road elements in the direction its traveling, unless it moves past the end of the road for the direction it is traveling. It this case, the car reverses direction at the end of the road. For example, if the is traveling left-down and the car is current at road element 3(with coordinates (22, 16) with speed 5, move() notes that this will move past the end of the road and sets the location to (20, 15) and reverses the direction to right-up. If the car is at road element 3 traveling left-down at speed 3, move() changes the location to (21, 15).

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

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions