Question
Vehicle is an interface that declares three methods to: Modify the gear number: sets the gear value to the new value passed as a parameter
Vehicle is an interface that declares three methods to: Modify the gear number: sets the gear value to the new value passed as a parameter Modify the speed: increments the Vehicles speed by the value passed Apply the break: will decrement Vehicles speed by the value passed
Car, Boat, Aircraft are three classes that implement Vehicle (They also define the size and color)
Truck, Van, Sailboat, Yacht, Helicopter, and Blimp are classes that inherit the three previous classes as shown in the diagram. (They differ by the size maximum number of passengers- and number of passengers each one has)
Write the java classes that is defined above. With the needed default constructor and at least one overloaded constructor for every class.
Please include all the setter, getter, toString methods Write the tester class that instantiate 3 Objects of each of the Truck, Van, Sailboat, Yacht, Helicopter,
and Blimp classes. For example: Truck C1 = new Truck() Car C2 = new Truck() Vehicle C3 = new Truck()
Invoke all the methods in all the classes, even if it will generate an error. Output the expected results, and the actual ones
For example
System.out.println(Testing getSize() + expected + 2 + passenger );
System.out.println(Testing getSize() + Actual + C1.getSize() + passenger );
If you will expect that invoking a method will give a syntax error, explain why in your out put statement and comment the statement that caused the error.
No need for the users entry. Document your code properly, dont forget @override. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is the code I have so far, please help me modify/complete it:
public interface vehicle
{
//abstract method to be implemented by the subclasses
public void gear(int gear);
public void speed(int speed);
public void breakk(int speed);
}
-----------------------------------------------
public class car implements vehicle {
//private member variables
private int size;
private String color; //physical properties of the car
private int speed;
private int breakk;
private int gear;
//constructor
public car(int size, String color, int speed, int breakk) {
this.size=size;
this.color=color;
this.speed=speed;
this.breakk=breakk;
this.gear=gear;
}
@Override
public String toString() {
return " the car's size and color is (" + size + "," + color+")";
}
//implement abstract methods defined in the interface vehicle
@Override
public void gear(int gear) {
this.gear = gear;
}
@Override
public void speed(int speed) {
speed++;
}
@Override
public void breakk(int breakk) {
breakk--;
}
}
-----------------------------------------------
//private member variables
private int size;
private String color; //physical properties of the car
private int speed;
private int breakk;
private int gear;
//constructor
public boat(int size, String color, int speed, int breakk) {
this.size=size;
this.color=color;
this.speed=speed;
this.breakk=breakk;
this.gear=gear;
}
@Override
public String toString() {
return " the car's size and color is (" + size + "," + color+")";
}
//implement abstract methods defined in the interface vehicle
@Override
public void gear(int gear) {
this.gear = gear;
}
@Override
public void speed(int speed) {
speed++;
}
@Override
public void breakk(int breakk) {
breakk--;
}
}
-----------------------------------------------
public class aircraft implements vehicle{
//private member variables
private int size;
private String color; //physical properties of the car
private int speed;
private int breakk;
private int gear;
//constructor
public aircraft(int size, String color, int speed, int breakk) {
this.size=size;
this.color=color;
this.speed=speed;
this.breakk=breakk;
this.gear=gear;
}
@Override
public String toString() {
return " the car's size and color is (" + size + "," + color+")";
}
//implement abstract methods defined in the interface vehicle
@Override
public void gear(int gear) {
this.gear = gear;
}
@Override
public void speed(int speed) {
speed++;
}
@Override
public void breakk(int breakk) {
breakk--;
}
}
-----------------------------------------------
public class truck extends car{
public int passenger_number;
//default and overloaded constructors
//public truck(int passenger_number){
//super(car);
//}
public int getPassenger_number() {
return passenger_number;
}
public void setPassenger_number(int passenger_number) {
this.passenger_number=passenger_number;
}
}
-----------------------------------------------
public class testVehicle{
public static void main(String[] args) {
// upcast
vehicle v1 = new car(5, red);
Vehicle Car Boat Aircraft Truck Van Sailboat Yacht Helicopter Blimp
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