Question: PLEASE PROVIDE A CODE IN JAVA PLEASE DO IT AS SOON AS POSSIBLE. Create a base class Car and it will have fields: name (data

PLEASE PROVIDE A CODE IN JAVA

PLEASE DO IT AS SOON AS POSSIBLE.

Create a base class Car and it will have fields: name (data type String), cylinders (data type int), engine (data type boolean), and wheels (data type int).

Write a constructor that receives name and cylinders as parameters and initialize the two fields. Set engine to true and wheels to 4.

Create appropriate getters.

Create methods startEngine, accelerate, and brake. These methods should return a message "Car -> startEngine()", "Car -> accelerate()" and "Car -> brake()"

Create 3 sub-classes: Honda, Toyota, Ford. In each of these classes, override the base class methods. The overridden methods should return a message "Honda -> startEngine()", "Honda -> accelerate()", "Honda -> brake()" for Honda. Override the base class methods for Toyota and Ford similar to Honda class.

In the demo class: Create objects of Car, Honda, Toyota and Ford classes passing the name and cylinder values to the respective constructor as follows:

Car: "Base Car", 8 Honda: "Honda Accord", 6 Toyota: "Toyota RAV4", 4 Ford: "Ford Truck F-250", 8

Create an array of Car class containing 4 elements and assign the Car, Honda, Toyota, and Ford objects to each of the element.

Use a loop to iterate through the array. The body of the loop should have a System.out.println statement that calls startEngine(), accelerate(), brake() methods for each element.

The output should be similar to the following:

Car -> startEngine() Car -> accelerate() Car -> brake() Honda -> startEngine() Honda -> accelerate() Honda -> brake() Toyota -> startEngine() Toyota -> accelerate() Toyota -> brake() Ford -> startEngine() Ford -> accellerate() Ford -> brake()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!