1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sloan [31]
2 years ago
6

Write a class named Car that has the following member variables: - yearModel. An int that holds the car’s year model. - make. A

string that holds the make of the car. - speed. An int that holds the car’s current speed. The class should have the following member functions: - Appropriate accessor functions to get the values stored in an object’s yearModel, make, and speed member variables. - accelerate function that adds 5 to the speed member variable each time it is called. - brake function that subtracts 5 from the speed member variable each time it is called.
Computers and Technology
1 answer:
Wewaii [24]2 years ago
6 0

Answer:

public class Car {

//Member variables    

private int yearModel;

   private String make;

   private int speed;

   //Constructor

   public Car(int yearModel, String make, int speed) {

       this.yearModel = yearModel;

       this.make = make;

       this.speed = speed;

   }

   //Accessor Methods getters and setters

   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;

   }

   //Accelerate function

   public void accelerate(){

       this.speed+=5;

   }

   // Brake function

   public void brake(){

       this.speed-=5;

   }

}

Explanation:

  • As required by the question, The class Car is created using Java programming language
  • The members variables, the constructor, The accessor methods are all created as required by the question (Please pay attention to the comments added to the code)
  • The accelerate and brake functions that add and subtract 5 from the speed member variable respectively are also created.
You might be interested in
3. The following code will not display the results expected by the programmer. Can
Elena L [17]

Answer:

ion k

Explanation:

7 0
3 years ago
Which of the following is an example of a tax?
Alik [6]
Medicare because it’s like insurance
5 0
2 years ago
Which of the following is most often added to safety glasses to provide better protection from impact and flying particles? A. S
Vesnalui [34]

the answer is side shields cause the side shields gives more protection to the eyes than just the lens because the flying objects and particals can still get into your eyes even with the safty glasses but with the side shields the total risk of injury percentage goes down because the side shields helps blocks the flying objects and particals that are trying to get into your eye from the side

8 0
3 years ago
One advantage of taking photographs under fluorescent light is that: Group of answer choices
Alexus [3.1K]

They tend to be dull.

7 0
2 years ago
1 Which skill-based video game requires quick reflexes and skills with weapons?
kirill [66]

The Answer to Number 1 is Shooter Games

The Answer to Number 2 is Dice Throwing

The Answer to Number 3 is Games are organized play

The Answer to Number 4 is Either Simulation or Adventure

The Answer to Number 5 is Stories have no rules to follow, you can learn from countless other lifetime through stories

The Answer to Number 6 is Setting

The Answer to Number 7 is False

The Answer to Number 8 is Objective

7 0
2 years ago
Other questions:
  • Approximately what percent of U.S. businesses have some form of remote work program? (from Chapter 1)
    14·1 answer
  • How would you say an hard drive works
    9·2 answers
  • When RadioButton objects are contained in a group box, the user can select only one of the radio buttons on the panel.
    12·1 answer
  • Which categories format cells
    14·2 answers
  • How to get this on your screen in 2k20 on Xbox
    14·2 answers
  • Discuss the different types of user-friendly interfaces and the types of users who typically use each.
    12·1 answer
  • The major difference between a template and another document is in _____.
    7·1 answer
  • What explains the discrepancy between the number of bytes you can
    13·1 answer
  • Write a function called mul_time that takes a Time_Elapsed object and a number and returns a new Time_Elapsed object that contai
    13·1 answer
  • marion is an iot developer working for a large organization. why does his supervisor want him to stay informed about the network
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!