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:
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