<h2>
Answer:</h2>
//Write the class definition for the class Car
public class Car {
//Declare the instance variables(fields)
int yearModel;
String make;
int speed;
//Declare the constructor: Make sure the constructor has
//the same name as the name of the class - Car.
//The constructor receives two parameters - yearModel and make.
//The parameters are then assigned to their respective fields.
//The speed field is given a value of zero.
public Car(int yearModel, String make){
this.yearModel = yearModel;
this.make = make;
this.speed = 0;
}
//Accessor method - get - for the yearModel
//returns the yearModel of the car
public int getYearModel() {
return yearModel;
}
//Accessor method - get - for the make
//returns the make of the car
public String getMake() {
return make;
}
//Accessor method - get- for the speed
//returns the speed of the car
public int getSpeed() {
return speed;
}
//Method accelerate() to increase the speed of the car by 5
//each time it is called
public void accelerate(){
this.speed += 5;
}
//Method brake() to decrease the speed of the car by 5
//each time it is called
public void brake(){
this.speed -= 5;
}
} //End of class declaration
<h2>
Explanation:</h2>
The code above has been written in Java. It contains comments explaining the code. Please go through the comments. The actual lines of code that are executable are written in bold-face to distinguish them from the comments.