Question

Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicyc...

Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicycle, ant the other encapsulating a motorized vehicle. A motorized vehicle has the following additional attributes: its engine volume displacement, in liters; and a method computing and returning a measure of horsepower which is the number of liters times the number of wheels. You also need to include a client class to test these two classes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Vehicle.java

public abstract class Vehicle {
   private String ownerName;
   private int noOfWheels;

   public Vehicle(String ownerName, int noOfWheels) {
       this.ownerName = ownerName;
       this.noOfWheels = noOfWheels;
   }

   public String getOwnerName() {
       return ownerName;
   }

   public void setOwnerName(String ownerName) {
       this.ownerName = ownerName;
   }

   public int getNoOfWheels() {
       return noOfWheels;
   }

   public void setNoOfWheels(int noOfWheels) {
       this.noOfWheels = noOfWheels;
   }

}
______________________

// Bicycle.java

public class Bicycle extends Vehicle {

   public Bicycle(String ownerName, int noOfWheels) {
       super(ownerName, noOfWheels);

   }

}
_______________________

// MotorVehicle.java


public class MotorVehicle extends Vehicle {
   private int engineVolume;

   public MotorVehicle(String ownerName, int noOfWheels, int engineVol) {
       super(ownerName, noOfWheels);
       this.engineVolume = engineVol;

   }

   public int getEngineVolume() {
       return engineVolume;
   }

   public void setEngineVolume(int engineVolume) {
       this.engineVolume = engineVolume;
   }

   public double horsePower()
   {
       return getNoOfWheels()*engineVolume;
   }
  
}

___________________________

// Test.java

public class Test {

   public static void main(String[] args) {
Bicycle b=new Bicycle("Kane Williams",2);
MotorVehicle m=new MotorVehicle("James",4,25);
System.out.println("Bicycle Info :");
System.out.println("Owners name:"+b.getOwnerName());
System.out.println("No of Wheels:"+b.getNoOfWheels());
System.out.println("\nMotorVehicle Info :");
System.out.print("Owners name:"+m.getOwnerName());
System.out.println("No of Wheels:"+m.getNoOfWheels());
System.out.println("Engine Volume Displacement:"+m.getEngineVolume());
System.out.println("Horse Power:"+m.horsePower());

   }

}
_______________________________

Output:

Bicycle Info :
Owners name:Kane Williams
No of Wheels:2

MotorVehicle Info :
Owners name:JamesNo of Wheels:4
Engine Volume Displacement:25
Horse Power:100.0

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicyc...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT