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]
3 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]3 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
Please respond not with answer but with comment.
aksik [14]

Answer:.I used to play it but now I don’t;—;

Explanation:

4 0
3 years ago
When we look for errors inside of our code on our own or with a partner , what is that called?
lutik1710 [3]
It’s called that he is cheating
6 0
2 years ago
Read 2 more answers
A function ________ contains the statements that make up the function.
mestny [16]

Answer:

A) definition

Explanation:

3 0
3 years ago
True or False: It is illegal to park in a location that you block or create a hazard for other vehicles.
Feliz [49]
The answer to question is true
5 0
3 years ago
Read 2 more answers
HELP!!!!!!!
Savatey [412]

Answer:

mouse - input

printer - output

keyboard - input

speakers - output

headset - both

6 0
3 years ago
Other questions:
  • What do radio telescopes use to gather and focus radio waves?
    14·2 answers
  • Mia is attending a team meeting to discuss how to prevent accidents. One of her teammates suggests pushing all the desks against
    15·2 answers
  • i will be doing an interview to someone so plz comment down below something random and you will automatically enter
    11·1 answer
  • How long does it take to be placed in a class on flvs?
    14·1 answer
  • ____ is the only automated disk-to-disk tool that allows you to copy data to a slightly smaller target drive than the original s
    5·1 answer
  • Which type of computer graphic can be blown up to a much larger size without getting distorted or losing quality?
    5·1 answer
  • How to simplify???? 2(-3x^2+6x+1)-2(4x^2-3x+1)<br><br>​
    7·1 answer
  • Why did Elena Gilbert Turn her humanity off when she was sired to Damon? (In The Vampire Diaries)
    14·1 answer
  • A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departme
    7·1 answer
  • _______ is a medium-range wireless network. ________ is a medium-range wireless network. Cellular radio LTE UWB Wi-Fi
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!