Question: For Java Create an external class called Car Write a class named car that has the following fields. yearModel: an int that holds the car's

For Java

Create an external class called "Car" Write a class named car that has the following fields.

yearModel: an int that holds the car's year model

make: a string that holds the make of the car

speed: an int that holds the car's current speed.

In additional, the class should have the following methods.

Constructor: the constructor should acccept the car's year model and make as arguments. These values should be assigned to the objects yearModel and make fields. The constructor should assign 0 to the speed field.

Appropriate accessor methods to get the values stored in an object's yearModel, make and speed fields. Something like getYearModel(), getMake, and getSpeed().

accelerate: the accelerate method should add 5 to each speed field each time it is called.

brake: the brake method should subtract 5 from the speed field each time it is called.

---

Additionally create a driver class, called CarDemo that accesses the car class and it's methods. Create an object of type car. Use the accelerate method 5 times, and use the break method 5 times. after each use of the accelerate and brake method, display the object's speed.

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!