Back to Challenge Set 15

Code Challenge: Ticket Price

Difficulty  

divider

The Brief

What they asked for
I run the planetarium box office. Children under 5 get in
free. Kids 12 and under pay $8. Seniors, 65 and over, pay
$9. Everybody else pays $14. I want to give it an age and
get the ticket price back, and then add up a whole family.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • The brief states every boundary in words — “under 5,” “12 and under,” “65 and over.” Each phrase tells you which comparison operator belongs there.
  • One method, one parameter, one returned price. Nothing is printed inside it.
  • The family total must come from adding the values your method returns, not from typing 45 anywhere.
  • Four bands means the order of your checks matters. Test an age on every boundary — 4, 5, 12, 13, 64, and 65 — before you trust it.

Sample Output

Sample Output
Age 4: $0.00
Age 9: $8.00
Age 40: $14.00
Age 42: $14.00
Age 70: $9.00
Family total: $45.00

This family is ages 4, 9, 40, 42, and 70. Your six boundary ages are the real test; this sample checks only one of them.


Submit

Your requirements list and your program file, named cc-ticket-price.

Commence Challenge