Question: 2 (Code only) Create a class called Car in a file called Car.java that has the following: A String field called make A String field

 2 (Code only) Create a class called Car in a file

2 (Code only) 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 separate main class that contains a main method (Hw3pr2.java).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. Name your main class Hw3pr2 and your main file Hw3pr2.java. Remember to submit both Hw4pr4.java and Car.java

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!