Adding exercise 2 code for CHAPTER 8