Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You must comment no everthing that you do Write a class named Car yearModel. The

ID: 3769181 • Letter: Y

Question

You must comment no everthing that you do

Write a class named Car yearModel. The yearModel field is an int that holds the car's year model.

·         speed. The speed field is an int that holds the car's current speed.

Constructor. The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's yearModel and make fields. The constructor should also assign 0 to the speed field.

·         accelerate. The accelerate method should add 5 to the speed field each time it is called.

·         Demonstrate the class in a program that creates a Car object, and then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method five times. After each call to the brake method, get the current speed of the car and display it.

Name the Class Lastname06Car and save the file as Lastname06Car.java. Down load the attached file Lastname06.java for the program that demonstrates the Class. Rename and modify and save the file with YOUR LAST NAME INSTEAD OF THE WORD LASTNAME. You will see within the code that line 7 will need to be modified to the name of the Class you create.

Not only must your program meet the requirements of the problem, you must also:

Comment further in the lab as necessary.

Your code should be "neat" with the proper indentation.

Explanation / Answer

/**
* Lastname06Car class
*/
class Lastname06Car {

   int yearModel;   // field that holds the car's year model
   String make;
   int speed;       // field that holds the car's current speed
   // constructor that accepts car's year model and make as arguments
   public Lastname06Car (int yearModel, String make) {
       super();
       this.yearModel = yearModel;
       this.make = make;
       this.speed = 0;
   }
   // accelerate method that adds 5 to speed
   public void accelerate() {
       this.speed += 5;
   }
   // brake method that subtracts 5 to speed
   public void brake() {
       this.speed -= 5;
   }
   // accessors and mutators of members of the class
   public int getYearModel() {
       return yearModel;
   }

   public void setYearModel(int yearModel) {
       this.yearModel = yearModel;
   }

   public String getMake() {
       return make;
   }

   public void setMake(String make) {
       this.make = make;
   }

   public int getSpeed() {
       return speed;
   }

   public void setSpeed(int speed) {
       this.speed = speed;
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote