Question: do it in Java code. Write a class named Car that has the following fields: o year. The year field is an int that holds

do it in Java code.
do it in Java code. Write a class named Car that has

Write a class named Car that has the following fields: o year. The year field is an int that holds the year the car was made. e make. The make field references a String object that holds the make of the car. o model. The model field references a string object that holds the model of the car. speed. The speed field is an int that holds the car's current speed. . In addition, the class should have the following constructor and other methods. o Constructor. The constructor should accept the car's year, make and model as arguments. These values should be assigned to the object's year, make and model fields. The constructor should also yssign 0 to the speed field. Accessors. Appropriate accessor methods should get the values stored in an object's year, make, model and speed fields. o accelerate. The accelerate method should add 5 to the speed field each time it is called. brake. The brake method should subtract 5 from the speed field each time it is called. Demonstrate the class in a program named DriveCar. This class should create a Car object, display the year, make and model of the car, and then call the accelerate method five times. Then, call the brake method five times. After each call to the accelerate and brake method, get the current speed of the car and display it

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!