Last part of assignment 1. Not pretty, but it works.

Output is not like the sample, but it passes the unit
test.