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, and 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. Write an application class utilizing these two classes.

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

// Please find the below code.

package been;

public abstract class Vehicle {

   private String ownerName;
   private int numWheel;
  
  
   public Vehicle() {
       // TODO Auto-generated constructor stub
   }

   public Vehicle(String name, int num) {
      
       this.ownerName = name;
       this.numWheel = num;
      
   }
}

package been;

public class MotorizedVehicle extends Vehicle {


private String ownerName; // owner's name
private int numWheels; // number of wheels
private double engineSize; // engine size in litres

public MotorizedVehicle() {}

public MotorizedVehicle(String name, int wheels, double size) {
this.ownerName = name;
this.numWheels = wheels;
this.engineSize = size;
}

public String getOwnerName() {
return this.ownerName;
}

public int getNumWheels() {
return this.numWheels;
}

public double getEngineSize() {
return this.engineSize;
}

public double getHorsePower() {
return (this.engineSize * this.numWheels);
}
}

R Markers □ Properties E snippets Console X Progress Search-Coverage Debug sterminatedTestVehicle [Java Application] C:Progra

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