Lesson 5. Capstone: Ticket to Mars

 

Welcome to the first challenge. It’s time to take everything covered in unit 1 and write a program on your own. Your challenge is to write a ticket generator in the Go Playground that makes use of variables, constants, switch, if, and for. It should also draw on the fmt and math/rand packages to display and align text and to generate random numbers.

When planning a trip to Mars, it would be handy to have ticket pricing from multiple spacelines in one place. Websites exist that aggregate ticket prices for airlines, but so far nothing exists for spacelines. That’s not a problem for you, though. You can use Go to teach your computer to solve problems like this.

Start by building a prototype that generates 10 random tickets and displays them in a tabular format with a nice header, as follows:

Spaceline        Days Trip type  Price
======================================
Virgin Galactic    23 Round-trip $  96
Virgin Galactic    39 One-way    $  37
SpaceX             31 One-way    $  41
Space Adventures   22 Round-trip $ 100
Space Adventures   22 One-way    $  50
Virgin Galactic    30 Round-trip $  84
Virgin Galactic    24 Round-trip $  94
Space Adventures   27 One-way    $  44
Space Adventures   28 Round-trip $  86
SpaceX             41 Round-trip $  72

The table should have four columns:

  • The spaceline company providing the service
  • The duration in days for the trip to Mars (one-way)
  • Whether the price covers a return trip
  • The price in millions of dollars