Question: Q2) Create a java package called Lab10-Q2 with a class called Q2 that has the main function with the below code. public static void main(String[]
Q2) Create a java package called Lab10-Q2 with a class called Q2 that has the main function
with the below code.
public static void main(String[] args) {
Mustang mustang = new Mustang();
mustang.changeGear(2);
mustang.speedUp(50);
mustang.applyBrakes(10);
System.out.println("Mustang present state :");
mustang.printStates();
}
Inside the same package create an interface named Car that has the following methods.
void changeGear(int a);
void speedUp(int a);
void applyBrakes(int a);
Create a class called Mustang that implements the Car interface. The Mustang class should
have the following
private int speed = 0;
private int gear = 0;
public void changeGear(int newGear)-changes the Mustang gear
public void speedUp(int increment)-increase the Mustang speed
public void applyBrakes(int decrement)-decrease the Mustang speed
public void printStates()-prints out the Mustang current speed and gear
Using the above driver the program should output the following
Mustang present state :
speed: 40
gear: 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
