Question

Car class Question Design a class named car that has the following fields: YearModel: The yearModel...

Car class Question

Design a class named car that has the following fields: YearModel: The yearModel field is an integer that holds the car's year model. Make: The make field references a string that holds the make of the car. Speed: The speed field is an integer that holds the car's current speed. In addition, the class should have the following constructor and other methods: Constructor: The constructor should accept the. car's year model and make as arguments. The values should be assigned to the object's yearModel and make fields. The constructor should also assign 0 to the speed field. Accessors: Design appropriate accessor methods to get the values stored in an object's yearModel, make, and speed fields. Accelerate: The accelerate method should add 5 to the speed field each time it is called. Brake: The brake method should subtract 5 from the speed field each time it is called. Next, design a program that creates a car object, and then cals the accelerate method fibe times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method 5 times. After each call to the brake method, get the current speed of the car and display it.

Thanks for the help guys (pseudocode and flowchart only) please no java code!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For the above problem the pseudocode is as follows:

  1. Begin
  2. Declaring and defining class named Car
  3. Variables for Car are declared as follows:
    1. Public variables
    2. int YearModel // it holds the car’s year model
    3. string Make // it holds the car’s make i.e. the brand
    4. int Speedfield // holds the current speed of the car
  4. Create and define constructor named Car, make it public // constructor name is same as class
  5. Declare Car as int year, string make
    1. YearModel is assigned the value of year
    2. Make is assigned the value of make
    3. Initialize Speedfield as 0
  6. Declare and define accessor methods
    1. int YEAR // to get the YearModel
      1. Takes no arguments
      2. Returns the YearModel
    2. string MAKE // to get the Make
      1. Takes no argument
      2. Returns the Make
    3. int SPEED // to get current speed
      1. Takes no arguments
      2. Returns Speedfield
    4. void Accelerate // add acceleration to current speed
      1. No return type
      2. Add 5 to the current speed when it is called.
    5. Void Brake // for braking mechanism
      1. No return type
      2. if Speedfield is greater than or equal to 5
      3. then subtract 5 from Speedfield
      4. else Speedfield is set to 0
  7. Initialize main method with void return
    1. Declare Car type variable c. // creating an object
    2. Input the values for c:
      1. c.YEAR
      2. c.MAKE
    3. Print the details of Car c
    4. Declare variables call a and b
    5. For a is equal to 0 and a is less than 5 continue // calling Accelerate method 5 times
      1. Call c.Accelerate()
      2. Print current speed calling c.SPEED()
    6. For b is equal to 0 and b is less than 5 continue // calling Brake method 5 times
      1. Call c.Brake()
      2. Print current speed calling c.SPEED.
      3. if c.Brake() is equal to zero // i.e. the Speedfield becomes 0 as we started with 0 and accelerate with 5 and braking with 5
      4. Print “CAR HAS BEEN STOPPED”
    7. End of main method
  8. End

The flow chart:

Add a comment
Know the answer?
Add Answer to:
Car class Question Design a class named car that has the following fields: YearModel: The yearModel...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python Design a class named Car that has the following fields: yearModel: The yearModel field is...

    python Design a class named Car that has the following fields: yearModel: The yearModel field is an Integer that holds the car’s year model. make: The make field references a String that holds the make of the car. speed: The speed field is an Integer that holds the car’s current speed. In addition, the class should have the following constructor and other methods: Constructor: The constructor should accept the car’s year model and make as arguments. These values should be...

  • java Write a class named Car that has the following fields: • yearModel: The yearModel field...

    java Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values...

  • Java Program Write a class named Car that has the following fields: yearModel- The yearModel field...

    Java Program Write a class named Car that has the following fields: yearModel- The yearModel field is an int that holds the car’s year model. make- The make field is a String object that holds the make of the car, such as “Ford”, “Chevrolet”, etc. speed- This speed field is an int that holds the car’s current speed. In addition, the class should have the following methods: Constructor- The constructor should accept the car’s year model and make as arguments....

  • Car Class Background: Write a class named Car that will be used to store information and...

    Car Class Background: Write a class named Car that will be used to store information and control the acceleration and brake of a car. Functionality: 1. Write a class named "Car” that has the following member variables: • year Model - 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 2. In addition the class should have the following member...

  • In Python Programming: Write a class named Car that has the following data attributes: _ _year_model...

    In Python Programming: Write a class named Car that has the following data attributes: _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed) The Car class should have an _ _init_ _ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed...

  • Second time posting please answer this question!!! Thankyou!! Please do it in visual studio C #...

    Second time posting please answer this question!!! Thankyou!! Please do it in visual studio C # and post copy of form.cs and designer.cs. Will give vgood review!!! In this module you learned about Classes and Multiforms. You will be completing one program for this module Write a class named Car that has the following member variables: year -    An int that holds the car’s model year. make - A string object that holds the make of the car. speed -...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • (C++)This is the problem that I'm supposed to write a program for: This is the layout...

    (C++)This is the problem that I'm supposed to write a program for: This is the layout that we are supposed to fill out for the project: If anything is unclear, comment and I'll try to clarify. Thank you! Objective Reading Dala Files Project This is a variation of ng challenge 133 de Write a class named Car that has the following pelvate member variables. model Year An ie car's uodd year. make A string that bolds the make of the...

  • java bluej Create a class called Vehicle, that contains five fields, current speed, power, accelerate, decelerate...

    java bluej Create a class called Vehicle, that contains five fields, current speed, power, accelerate, decelerate and top speed, all of which type is int.  Define a constructor that takes and sets the accelerate, decelerate; sets the power to 20, and top speed to 120. Leave the current speed as 0. Also define a constructor that takes no parameters. The power field should be set to the value of 30 in this constructor, top speed to 160, and accelerate and decelerate...

  • Question 65 (15 points) Code a Car class with 3 private member variables make, speed, and yearMod...

    Use C++ Question 65 (15 points) Code a Car class with 3 private member variables make, speed, and yearModel. In the public section, one constructor passed the yearModel and make and three accesor member methods. Member functions and variables should be in ascending alphabetic order. Question 65 (15 points) Code a Car class with 3 private member variables make, speed, and yearModel. In the public section, one constructor passed the yearModel and make and three accesor member methods. Member functions...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT