chapter 9 code example impemented