Create a class named vehicle that acts as a super class


Create a class named Vehicle that acts as a super class for vehicle types. The Vehicle class contains private variables for the number of wheels and the average number of miles per gallon. The Vehicle class also has a constructor with integer arguments for the number of wheels and average miles per gallon and a toString() method that returns a String containing these values.

Create two subclasses, Car and MotorCycle, that extend the Vehicle class. Each subclass contains a constructor that accepts the mile-per-gallon value as an argument and forces the number of wheels to the appropriate value-2 for MotorCycle and 4 for Car.

Write a UseVehicle class to instantiate one Vehicle object, one Car object, one MotorCycle object, and display each object's values.

You need to submit original .java files (Vehicle.java, Car.java, MotorCycle.java, and UseVehicle.java) as an attachment to your initial response. (Please do not copy/paste the whole file code into your response.) Zip them into a single .zip file and attach the .zip file to your post. In the initial response itself, please provide comments and explanations of your solution with a proper UML diagram illustrating class hierarchy.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Create a class named vehicle that acts as a super class
Reference No:- TGS0918388

Now Priced at $30 (50% Discount)

Recommended (96%)

Rated (4.8/5)