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

Use JAVA 1. Create an interface called Manual that has two methods, gearUp and g

ID: 3802506 • Letter: U

Question

Use JAVA 1. Create an interface called Manual that has two methods, gearUp and gearDown, which does not take any argument. They both return void.

2. Then one abstract class called Vehicle, which we will use to create two subclasses: Car and Bicycle.

3. All vehicle should have a current gear (int) and a registration number (String) but only Car have a license plate (String). All cars have 5 speed (from 1 to 5) and all bicycles have 18 speed (from 1 to 18). You also need an int constant (MAX_GEAR) that indicate the maximum gear.

4. Create an initializer constructor for every class to initialize their data member(s). [hint: you should have 3 and only 3 constructors in total]

5. Implement gearUp and gearDown for both Car and Bicycle. Simply increase current gear if it has not reach the largest possible gear; otherwise, does nothing. gearDown should decrease current gear if it is greater than 1; otherwise, does nothing.

Explanation / Answer


interface Manual {
    void gearUp();
    void gearDown();
}


class Car extends Vehicle {
    String lisencePlate;
    protected final int MAX_GEAR ;

    public Car(String lisencePlate, int gear, String regNo) {
        super(gear, regNo);
        this.lisencePlate = lisencePlate;
        MAX_GEAR = 5;
    }
  
    @Override
    public void gearDown() {
        if (gear > 1)
            gear--;
    }
  
    @Override
    public void gearUp() {
        if(gear < MAX_GEAR)
            gear++;
    }

  
}

class Bicycle extends Vehicle {

    protected final int MAX_GEAR ;
    public Bicycle(String regNo) {
        super(1, regNo);
        MAX_GEAR = 18;
    }
  
    @Override
    public void gearDown() {
        if (gear > 1)
            gear--;
    }
  
  
    @Override
    public void gearUp() {
        if(gear < MAX_GEAR)
            gear++;
    }

}

/**
*
* @author Sam
*/
public abstract class Vehicle implements Manual{
    protected int gear;
    protected final String regNo;

    public Vehicle(int gear, String regNo) {
        this.gear = gear;
        this.regNo = regNo;
    }
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote