Question
For Java Create an external class called Car Write a class named car that has the following fields. yearModel: an int that holds the car's
For Java
Create an external class called "Car" Write a class named car that has the following fields.
yearModel: an int that holds the car's year model
make: a string that holds the make of the car
speed: an int that holds the car's current speed.
In additional, the class should have the following methods.
Constructor: the constructor should acccept the car's year model and make as arguments. These values should be assigned to the objects yearModel and make fields. The constructor should assign 0 to the speed field.
Appropriate accessor methods to get the values stored in an object's yearModel, make and speed fields. Something like getYearModel(), getMake, and getSpeed().
accelerate: the accelerate method should add 5 to each speed field each time it is called.
brake: the brake method should subtract 5 from the speed field each time it is called.
---
Additionally create a driver class, called CarDemo that accesses the car class and it's methods. Create an object of type car. Use the accelerate method 5 times, and use the break method 5 times. after each use of the accelerate and brake method, display the object's speed.
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