Code for Exercise 3.5