Question: 1- Use inheritance to implement the following classes: A : A Car that is a Vehicle and has a name, a max_speed value and an
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the
number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the number_of_engines it has. Add public methods to set and get the values of these variables. When an airplane is printed (using the toString method), its name, max_speed and number_of_engines are shown.
C: Write a VehicleDemo.java class that does the following:
1- Creates an instance of a Car and an Airplane class.
2- Assign values to the name, speed, number_of_cylinders (for the Car object) and
number_of_engines (for the Airplane object) variables.
3- Compares which vehicle goes faster and prints the result.
4- Prints the instances of the car and airplane classes.


2- Add the following changes to the above problem: A: Make the Vehicle an abstract class and add the following abstract method to it: double runningCost(int hour); Which receives the hours of operation as a parameter and returns the running cost of the vehicle. The Car andAirplane classes will implement this method as follows: 1- For the Car class, define a private double constant called COST PER CYLINDER PER HOUR 10.5. The runningCost of a Car will be equal to hours COST PER CYLINDER PER HOUR number of cylinders 2- For the Airplane class, define a private double constant called COST PERLENGINE PER HOUR- 25.3. The runningCost of an Airplane will be equal to: hours COST PER ENGINE PER HOUR number of engines B: Write an interface called maintainable, which has the following method: double maintenanceCost(double costPerUnit); t receives the cost per unit of an engine or cylinder and returns the maintenance cost. The Car and Airplane classes will implement this interface as follows: 1- For the Car class, the maintenance cost of a Car will be equal to: costPerUnit number of cylinders
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
