6. (19 pts) Consider the following code for a class representing a car public cl
ID: 3789349 • Letter: 6
Question
6. (19 pts) Consider the following code for a class representing a car public class Car private string makeAndModel the car's make and model private double speed; roughly indicates how fast the car is public void race (Car c) incomplete to be written in part (d) a. Gpus rite "setter" (mutator) methods for the two instance variables. Your setter for speed should not allow a negative value to be assigned. b. 2 pts) Write "getter" (accessor methods for the two instance variables. c. 3 pts Write a constructor that allows the make to specified at the time a Car object is and speed be created. Your constructor should call your setters from part (a).Explanation / Answer
a)-Setters for both variable-
public void setSpeed(int speed) {
if(s>0)
{
this.speed = speed;
}
}
public void setmakeAndModel(int makeAndModel) {
this.makeAndModel = makeAndModel;
}
b)-Getters for both variable-
public String getSpeed() {
return speed;
}
public void setSpeed(int speed) {
if(s>0)
{
this.speed = speed;
}
For other question tobe answered please provide as seprate questions
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.