Also design a test program that creates a car object then


Design a Java class named Car with the following fields:

- yearModel,

- make: references a string,

- speed: holds the car's current speed.

In addition, it should also have the following constructor and other methods:

- Constructor: should assign 0 to the speed field, accept the year model and make as arguments which are assigned to the object's yearModel and make fields respectively.

- Accessors: methods to get the values stored in yearModel, make and speed fields.

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

- brake: should subtract 5 from the speed field when called.

Also design a test program that creates a Car object, then calls the accelerate method five times, and after each call gets the current speed of the car and displays it. Then it calls the brake method five times, and after each call gets the current speed and displays it.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Also design a test program that creates a car object then
Reference No:- TGS01254698

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)