Solution to Programming Exercise 2