Question: AcceleratingCar.java Write a class named Car.java that has the following fields: yearModel. The year Model field is an int that holds the car s year

AcceleratingCar.java
Write a class named Car.java that has the following fields:
yearModel. The year Model field is an int that holds the cars year model.
make. The make field references a String object hat holds the make of the car.
speed. The speed field is an int that holds the cars current speed.
In addition, the class should have the following constructor and other methods.
Constructor. The constructor should accept the cars year model and make as arguments. These values should be assigned to the objects yearModel and make fields. The constructor should also assign 0(zero) to the speed field.
Accessors. Appropriate accessor methods should get the values stored in an objects 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.
Below is a little review of UML as demonstrated in class.
AcceleratingCar.java
Topics covered: UML Diagrams, Using Objects, Instance Variables (Fields), Constructors, Mutator Methods, Accessor Methods, Other Methods
This assignment is to introduce you to UML Diagrams and how to use them to create your classes. Attached are 3 files. Complete the TODO's. One of them is an UML Diagram. Download that and use it to code your car class. Your class should have appropriate fields, constructors, mutator and accessor methods, and a brake method and an accelerate method.
_______________________
Car
______________________
- yearModel: int
- make: String
- speed: int
______________________
+ Car(carYear:int, carMake: String)
+ setYearModel(carYear: int)
+ setMake(carMake:String)
+setSpeed(carSpeed: int)
+getYearModel():
+ getMake()
+ GetSpeed()
+accelerate()
+ brake()
The top of the UML diagram contains the class name. Create a class named "Car"
The next section of the UML diagram contains your fields. It starts with the variable name and then goes to the type. These fields can be accessed anywhere in your Car class. If you make them private they will not be able to be accessed from anywhere else. Create three private instance variables to store the cars year model, the make of the car, the cars current speed.
The last part of the UML diagram has the methods inside the class. There are 4 types of methods: Constructors, Mutators, Accessors, and Other methods.
Create a constructor that accepts the cars year model (y: int) and make (m: String) as arguments. These values should be assigned to the objects yearModel and make fields. The constructor should also assign 0 to the speed field.
There are three setters listed in the UML Diagram. Add them in. These methods should get the values stored in an objects yearModel, make, and speed fields.
There are three getters listed in the UML Diagram. Add them in. These methods return the values yearModel, make, and speed fields.
The last bit of the UML Diagram are other methods. The accelerate method should add 5 to the speed field each time it is called. The brake method should subtract 5 from the speed field each time it is called.

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 Databases Questions!