Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 users 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

What did they do? What did they say?

Answered: 1 week ago