Question: Use UML instead of pseudocode for this program also. Write a class named Car that has the following attributes ( fields ) : yearModel The

Use UML instead of pseudocode for this program also. Write a class named Car that has the following attributes (fields):
yearModel The yearModel attribute holds the cars year model (example: 1999)
make The make attribute holds the make of the car (example: Ford)
speed The speed attribute holds the cars current speed
The Car class should have the following constructors and other methods:
The class should have two constructors: (overloaded)
The first constructor should accept the car's year model and make as arguments. These values should then be assigned to the car's yearModel and make This constructor should assign 0 to the speed attributeThe second constructor should be a default constructor that accepts no arguments. The constructor should set the yearModel and make attributes to the empty String ("") and the speed attribute to 0
Get Method: The class should have get methods for all of the attributes: yearModel, make, and speed.
Set Method: The class should have set methods for all of the attributes: yearModel, make, and speed.
Do not allow the speed attribute to be set to less than zero. If an attempt is made to set it to less than zero, do not set the speed attribute, leave it as it is.
Accelerate Method: The accelerate method should add 5 to the speed attribute each time it is called. Note it is a void method with NO parameters and NO printing.
Brake Method: The brake method should subtract 5 from the speed attribute each time it is called (if speed goes negative, set it to 0). Note it is a void method with NO parameters and NO printing.
You should save your car class file as Car.java.
Next create a program named ACarTest.java to utilize the Car class you created. The program should create a car object with a yearModel of 2017 and a make of Jeep using the first constructor that take the year model and make. Then create a car object with default constructor and input the year model and make. Then use set methods to set the yearModeland make using the inputs (recommend 2012 and Honda).
Then print the information for each car.
The program should then call one of the car object's accelerate method 5 times. After each call to the accelerate function the program should get and display the car objects current speed. The program should then call the car objects brake function 5 times. After each call to the brake function, the program should get and display the cars current speed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!