Coding Practice - Trip Simulator

Your client wants you to create a Trip Simulator. Apparently, your client hates to fly, so they drive across the country to find oddities to purchase and resell. Not trusting ATMs, they pay for everything in cash. The fear of getting robbed while they are traveling leads them to bring as little cash as possible with them. This fear has led to them running out of money on past trips. They want you to create an application that will tell them exactly how much cash to bring. Your application must account for the expenses they will occur on the trips. Also, they want to see a mile by mile account of the expenditure since, believe it or not; they don’t entirely trust you either.

Gather User Information

The system should store the following information.

  • Vehicle Miles Per Gallon

  • Current Price Per Gallon

  • Miles to Destination

  • Hotel Price Per Night

  • Number of Nights


Driving to the Destination

Once you have this information, you are to do a mile per mile simulation of the trip. Calculate the cost of filling an empty tank before departure. Every time the vehicle runs out of gas, stop to refuel and track the cost.


Let the user know how many miles they have traveled so far and asked if they want to spend any money on food or drink. Track any money spend on food and drinks.


Daily Expenses

After you have completed the first simulation, simulate the daily routine of the user for each night they are staying at the destination. Every day they are in town capture the following


  • Amount spent on each meal (breakfast, lunch, dinner, snack)

  • Amount spent on purchasing Oddities

  • Amount spent on other business costs

Driving Back Home

Now it’s time to drive back home. Calculate the cost of filling an empty tank before departure. Then proceed to simulate the drive home the same way you did the drive to the destination.


Every time the vehicle runs out of gas, stop to refuel and track the cost. Let the user know how many miles they have traveled so far and asked if they want to spend any money on food or drink. Track any money spend on food and drinks.


Expense Report

After the three simulations have run, you should have a full record of what the trip will cost the user. Display the information to them in the way described below.


Your simulated trip has completed. On your drive to your destination, you stopped [number of times] times and spent [$$$]. While you were in town, you spent a total of [$$$]. On your way home, you spent [$$$].


Your total cost for the trip was [$$$].


Your itemized breakdown is:

Fuel : [$$$]

Food : [$$$]

Lodging : [$$$]

Oddities : [$$$]

Other Costs : [$$$]


139 views0 comments

Recent Posts

See All