Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions