here is the inheritance java please help me to get Motorcycl
here is the inheritance java. please help me to get Motorcycle.java thankyou
Vehicle.java
public abstract class Vehicle {
private int numWheels;
private boolean licenseRequired;
public Vehicle (int numWheels, boolean licenseRequired) {
//finish constructor
this.numWheels = numWheels;
this.licenseRequired = licenseRequired;
}
protected int getNumWheels () {
//finish method
return numWheels;
}
protected void setNumWheels(int numWheels) {
//Finish this method
this.numWheels = numWheels;
}
protected boolean getLicenseRequired() {
//finish method
return licenseRequired;
}
protected void setLicenseRequired(boolean licenseRequired) {
//finish method
this.licenseRequired = licenseRequired;
}
public abstract int costOfMaint (int miles);
public abstract boolean updateNumWheels(int numWheels);
}
Complete the constructor, and the accessors / mutators (getters and setters) in the class. DO NOT change any signatures in the class.
Motorcycle.java
Implement this concrete class of Vehicle using inheritance. The class should have one private instance
variable called cost (no other instance variables allowed) and the constructor of the class should be:
public Motorcycle (int cost)
You should implement the abstract methods and the accessors and mutators for the instance variable.
The formula for the costOfMaint method is (cost * miles + 10). The method updateNumWheels should
update the number of wheels for the motorcycle only if the input is either 2 or 3). A license is required
and the default number of wheels is 2.
Solution
Motorcycle.java
public class Motorcycle extends Vehicle
{
private int costOfMaint;
public Motorcycle(int cost,int numWheels,boolean LicenseRequired)
{
super(numWheels,LicenseRequired);
this.costOfMaint = cost;
}
public int costOfMaint (int miles)
{
return (costOfMaint*miles +10);
}
public boolean updateNumWheels(int numWheels)
{
if(numWheels ==2 || numWheels==3)
setNumWheels(2);
setLicenseRequired(true);
return true;
}
}
HelloWorld.java
public class HelloWorld{
public static void main(String []args)
{
Motorcycle m=new Motorcycle(25,2,true);
System.out.println(\"Update Number Of Wheels=\" +m.updateNumWheels(2) );
System.out.println(\"Cost of Maintenace=\" +m.costOfMaint(100) );
}
}
Output:
Update Number Of Wheels=true
Cost of Maintenace=2510

