Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i have a class Vehicle , its the parent class , and i have a three child class\'

ID: 3587969 • Letter: I

Question

i have a class Vehicle , its the parent class , and i have a three child class's and every one of them have a child

and i just need to have a simple varibels and methodes in every class so i can test the in them test class

class Vehicle {

private String name;

private String size;

private int currentVelocity;

private int currentDirection;

   Vehicle(String name, String size) {

this.name = name;

this.size = size;

this.currentVelocity = 0;

this.currentDirection = 0;

}

public void steer(int direction) {

this.currentDirection += direction;

System.out.println("Vehicle.steer(): Steering at " + currentDirection + " degrees.");

}

public void move(int velocity, int direction) {

   currentVelocity = velocity;

currentDirection = direction;

System.out.println("Vehicle.move(): Moving at " + currentVelocity + " in direction " + currentDirection);

}

public String getName() {

return name;

}

public String getSize() {

return size;

}

public int getCurrentVelocity() {

return currentVelocity;

}

public int getCurrentDirection() {

return currentDirection;

}

public void stop() {

this.currentVelocity = 0;

}

}

class spaceship extends Vehicle { }

class airplane extends spaceship {  }

class boat extends Vehicle { }

class motorboat extends boat {  }

class motorbike extends Vehicle {  }

class scooter extends motorbike {  }

Explanation / Answer

public class Vehicle {

private String name;

private String size;

private int currentVelocity;

private int currentDirection;

Vehicle(String name, String size) {

this.name = name;

this.size = size;

this.currentVelocity = 0;

this.currentDirection = 0;

}

public void steer(int direction) {

this.currentDirection += direction;

System.out.println("Vehicle.steer(): Steering at " + currentDirection + " degrees.");

}

public void move(int velocity, int direction) {

currentVelocity = velocity;

currentDirection = direction;

System.out.println("Vehicle.move(): Moving at " + currentVelocity + " in direction " + currentDirection);

}

public String getName() {

return name;

}

public String getSize() {

return size;

}

public int getCurrentVelocity() {

return currentVelocity;

}

public int getCurrentDirection() {

return currentDirection;

}

public void stop() {

this.currentVelocity = 0;

}

}

class spaceship extends Vehicle {

private int altitude;

spaceship(String name, String size, int alt) {

super(name, size);

this.altitude = alt;

}

public int getAltitude() {

return altitude;

}

public void setAltitude(int altitude) {

this.altitude = altitude;

}

}

class airplane extends spaceship {  

private String type; // boeing, air bus

airplane(String name, String size, int alt, String type){

super(name, size, alt);

this.type = type;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

}

class boat extends Vehicle {

String type;

boat(String name, String size, String type){

super(name, type);

this.type = type;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

}

class motorboat extends boat {  

String comp;

motorboat(String name, String size, String type, String comp){

super(name, size, type);

this.comp = comp;

}

public String getComp() {

return comp;

}

public void setComp(String comp) {

this.comp = comp;

}

}

class motorbike extends Vehicle {

int engine;

motorbike(String name, String size, int engine){

super(name, size);

this.engine = engine;

}

public int getEngine() {

return engine;

}

public void setEngine(int engine) {

this.engine = engine;

}

}

class scooter extends motorbike {  

private String companyName;

scooter(String name, String size, int engine, String comp){

super(name, size, engine);

this.companyName = comp;

}

public String getCompanyName() {

return companyName;

}

public void setCompanyName(String companyName) {

this.companyName = companyName;

}

}