Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Create a class named Vehicle that acts as a superclass for vehicle types. The Vehicle class contains private variables for the number of wheels and...

Create a class named Vehicle that acts as a superclass for vehicle types. The Vehicle class contains private variables for the number of wheels and the average number of miles per gallon (MPG).  For each of these variables – create the proper get and set methods. The Vehicle class also contains a constructor with integer parameters for the number of wheels and average MPG. Create two subclasses, PassengerCar and Truck that extend the Vehicle class. The PassengerCar class will have an additional field  fuelTankCapacity and the method MaximumDistanceDriven, which calculate the maximum ride distance using the proper  MPG and fuel tank capacity values. The Truck class has the additional cargoLoad field. Each subclass contains a constructor that accepts the MPG value and forces the number of wheels to the appropriate values – 4 for a PassengerCar and 8 for a Truck. The PassengerCar constructor also accepts fuel tank capacity value, and the Truck constructor accepts the cargo load value. All classes contain appropriate get and set methods for each newly added field.

Write a UseVehicles class to instantiate three objects making use of proper overloaded class constructors: one object of the Vehicle class, one object of the PassengerCar class and one object of the Truck class. When doing so, accept the user input and provide proper values for each the fields of each object (use Scanner of JOptionPane classes to implement a user’s input).

Display the content of every data field in the newly created object: the number of wheels and average number of miles per gallon values for the Vehicle object; the number of wheels, miles per gallon, fuel tank capacity and maximum distance driven for a passenger car; number of wheels, average number of miles per gallon and cargo capacity for a Truck object.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question