Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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 to the speed field each time it is called.
Brake. The brake method should subtract 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 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
CarcarYear:int, carMake: String
setYearModelcarYear: int
setMakecarMake:String
setSpeedcarSpeed: 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 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 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 to the speed field each time it is called. The brake method should subtract from the speed field each time it is called.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started