Question: Design a class named Car that has the following fields: yearModel: an int instance variable that holds the cars year model. make: a string instance
Design a class named Car that has the following fields:
- yearModel: an int instance variable that holds the cars year model.
- make: a string instance variable that holds the make of the car.
- speed: an int instance variable that holds the cars current speed.
In addition, the class should have the following methods.
- Constructor 1: no-arg constructor set the yearModel, make and speed to 2000, Nissan and 4, respectively.
- Constructor 2: this is an overloaded constructor. This constructor should accept the cars year model, speed, and make as arguments. These values should be assigned to the objects yearModel, speed and make fields.
- Accessor (getters): appropriate accessor methods to get the values stored in an objects yearModel, make, and speed fields.
- Mutator (setters): appropriate mutator methods to store values in an objects yearModel, make, and speed fields.
- toString: returns a string describing the objects yearModel, make and speed.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
