Question: Race Car Simulator Create a Race Simulator As always provide proper encapsulation, use proper naming conventions. First create a racecar class with the following: A

Race Car Simulator

Create a Race Simulator

As always provide proper encapsulation, use proper naming conventions.

First create a racecar class with the following:

A double that represents the number of laps

A string that is the drivers name

An integer between 0-99 that is the cars number

An integer between 0-99 that represents the gas level of the car

0 being empty and 99 being full

An integer between 0-99 that represents the wear level of the tires

0 being completely worn out and 99 new

A boolean value that indicates that the car is in a pit stop

Provide a constructor that does the following:

Parameters:

Driver Name

Number (set to 0 if not valid)

Set the following:

Tire condition to 99

Gas level to 99

Pit stop to false

Override the < operator to compare the position in the race so that the standard library sort will sort the race cars from high to low.

Override the assignment operator.

Override the ++ operator. (run the tick method)

Provide getters for all instance variables but no setters.

Provide a method that decreases the gas level by one (never let the gas level be negative).

Provide a method that decreases the tire condition by one (never let the tire condition be negative).

Provide a method that returns the name of the driver the position on the track and the lap number

For example:

Bob picks up speed down the back stretch on lap 197

Fred picks up speed down the back stretch on lap 198

Alex flashes down the front stretch toward the finish line on lap 199

Danica flashes down the front stretch toward the finish line on lap 198

Provide a pitStop method that sets both the gas level and tire condition to 99 and pit stop to false.

To simulate the passage of time create a tick() method that our simulator can call.

Here is a pseudocode for what it should do:

public void tick() {

if we dont need a pit stop:

increase the lapCount by .15 + a random amount of hundredths (,01,.02,.03) between 0 and .1 decreaseGas();

there is a ten percent chance we will decrease the gas one more

decreaseTireCondition();

there is a ten percent chance we will decrease the tire condition one more

if gasLevel < 10 or tireCondition < 10 indicate we need a pitstop

If we need a pitstop do one.

}

Our track is Daytona:

You will need to convert the feet to a percent and compare it to the decimal portion of the lap count.

Map of Daytona track.

https://en.wikipedia.org/wiki/File:Daytona_International_Speedway.svg

Position Ends at (in feet)

down the front toward turn one 1900

Into turn one 2700

Out of turn one 3500

Into turn two 4300

Out of turn two 5100

BackStretch 8100

Into turn three 8900

Out of turn three 9700

Into turn four 10500

Out of turn four 11300

Down Front Stretch toward the finish line 13200

Note the lap should be displayed as an integer. Also print out that the driver headed to the pit stop if the pit stop indicator is true.

The Simulation

The simulation should loop through the cars and call the tick method.

Eventually one of the cars should go past the number of laps for a complete (200 or more)

Psuedocode:

Keep looping while the race is not over

Sort the cars () using the standard library sort:

sort(carVec.begin(), carVec.end())

call method to update each of the cars

if the race is not over print all the cars

if the race is over stop looping

Print out the winner

Print out the second place driver

The end of the simulation might look like this:

Bob picks up speed down the back stretch on lap 197

Fred picks up speed down the back stretch on lap 198

Alex flashes down the front stretch toward the finish line on lap 199

Danica flashes down the front stretch toward the finish line on lap 199

___________________________________________

Bob dives into turn three on lap 197

Fred explodes into turn four on lap 198

Alex flashes down the front stretch toward the finish line on lap 199

Danica down the front stretch toward turn one on lap 199

___________________________________________

Alex wins!

Danica is the runner up!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!