Question: write a java program for below instruction *Simple Vehicle Simulator* 1) Uses a Vehicle class that defines a velocity, position & direction as private hidden

write a java program for below instruction

*Simple Vehicle Simulator* 1) Uses a Vehicle class that defines a velocity, position & direction as private hidden data. 2) Allow the simulator to create vehicle object at the specific location with velocities in specific directions. The simulator an get the velocity, direction & position. 3) Allows changing velocity by specifying acceleration (positive and negative)time. 4) Allows changing the direction by specifying a value in degrees 5) Allows display of where the vehicle would be after 't' time unit given current velocity position & direction. 6) Allow change of position of the vehicle based on current velocity, position & direction.

*Use below code as a template*

package vehicle;

public class Vehicle {

// should be private

double velocity;

double x;

double y;

double direction;

public Vehicle(double v, double x, double y, double d) {

// d is given as degrees, you should store it internally

as radians

}

public double getVelocity() {

}

public double getDirection() {

// return direction in degrees not radians

}

public double [] getPosition() {

// return an array of doubles as the x, y pair

}

public void changeVelocity(double accelartion, int time) {

// acceleration can be positive or negative

// velocity is changed based on duration of acceleration

}

public void changeDirection(double nd) {

// change the direction

// the parameter nd is in degrees

// store the result in radians

}

public double [] showNewPosition(int t) {

// return the new x,y pair based on travelling for time t

// based on current velocity, direction and position

// does not change the vehicle's position

}

public void changePosition(int t) {

// changes the x,y pair based on travelling for time t

// based on current velocity, direction and position.

}

public String toString() {

// override the Object toString method to produce a

formatted string

// representation of a vehicle:

// ""

}

public static String toString(double [] p) {

// overloading of toString that takes an array of two

doubles

// and returns a position string: "(x,y)"

}

// You will note that the calculations you perform using toRadians,

toDegrees, cos, sin

// and floating point arithmetic are not exact and the raw display

of values is messy

// this method produces a floating value with no more than two

decimal places.

private double rndTo2DP(double d) {

// rounds d to have two decimal places

return Math.round(100*d)/100.0;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!