Implemented exercise 3 from chapter 3.