JAVA HELP A TEST DRIVE Create a class called Car in a file c

 ************JAVA HELP*************** A TEST DRIVE Create a class called Car in a file called Car.java that has the following:  - A String field called make  - A String field called model  - An int field called mileage  - An int field called speed  - A constructor method that accepts the car\'s make, model as arguments and assigns them to the class fields. Also set the car\'s speed and mileage to be 0.  - A method called accelerate - Increases the speed of the car by 5  - A method called brake - Decreases the speed of the car by 10  - An accessor method called getSpeed - This should just return the value of the speed field.  - An accessor method called getMileage - This should just return the value of the mileage field.  - A mutator method called setMileage - This should change the value of the mileage field to the given argument.  Write a seperate main class that contains a main method. In the main, create a Car object with the required arguments (make up some values, no need to ask the user).  Drive your new car by writing a loop that calls accelerate on your Car object 10 times.  In each iteration, after accelerating use your accessor method to get and display the speed of your car. Also update and display the mileage of your car by adding the value of the speed. Finally, stop driving by calling your brake method. Keep calling this method until your speed is 0. Display current speed and update your mileage everytime you brake.  Note: You need to be using an instance of your Car class. Nothing (except the main method) should be static. 

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

----------------------------------------------------------------

OUTPUT:

Current speed: 5
Mileage: 5
Current speed: 10
Mileage: 10
Current speed: 15
Mileage: 15
Current speed: 20
Mileage: 20
Current speed: 25
Mileage: 25
Current speed: 30
Mileage: 30
Current speed: 35
Mileage: 35
Current speed: 40
Mileage: 40
Current speed: 45
Mileage: 45
Current speed: 50
Mileage: 50
Brake applied.
Brake applied.
Brake applied.
Brake applied.
Brake applied.
Car stopped!

 ************JAVA HELP*************** A TEST DRIVE Create a class called Car in a file called Car.java that has the following: - A String field called make - A

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site