Answer:
// The class car is defined
public class Car {
// instance variable yearModel
private int yearModel;
// instance variable make
private String make;
// instance variable speed
private int speed;
// empty constructor
// with instances inside it
// the instances are from the question
public Car(){
yearModel = 2000;
make = "Nissan";
speed = 4;
}
// overloaded constructor
// constructor defined with three arguments
public Car(int yearModel, String make, int speed) {
// the arguments are assigned to the object's variable
this.yearModel = yearModel;
this.make = make;
this.speed =speed;
}
// setter(mutator) method
public void setYearModel(int yearModel){
this.yearModel = yearModel;
}
// setter(mutator) method
public void setMake(String make){
this.make = make;
}
// setter(mutator) method
public void setSpeed(int speed){
this.speed = speed;
}
// getter(accessor) method
public int getYearModel(){
return yearModel;
}
// getter(accessor) method
public String getMake(){
return make;
}
// getter(accessor) method
public int getSpeed(){
return speed;
}
// toString is override to display the car object properties
public String toString(){
return "Car's year model: " + getYearModel() + ", make: " + getMake() + ", speed: " + getSpeed();
}
}
Explanation:
The code is well commented.