Question: IN JAVA: Construct a calling class and a Car class as follows: Car Class: Properties: Make (String), Year(int), Color(String), Speed (int) Methods: All getter, setter
IN JAVA: Construct a calling class and a Car class as follows:
Car Class:
Properties: Make (String), Year(int), Color(String), Speed (int)
Methods:
All getter, setter methods
Accelerate ( increase speed : 15MPH if year < 2010, 30 MPH >= 2010)
Brake ( lower speed : 10 MPH if year < 2010, 5 MPH if year >= 2010, speed always >=0)
Stop (speed = 0)
Calling Class
Create an array of 10 cars. Give them random colors and makes of your choice. Remember to assign each a random color and make (do not hard code). Also , select a random year for a car, but when done, half the cars should have a year >=2010. Initial Speed is zero.
Do the following 100 times
Pick a random car
Randomly select Brake, Accelerate or Stop method (equal probabilities)
Invoke the selected method chosen for the car chosen
After the loop, print out the car number, year, make, color and final speed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
