solved exercise 2 in chapter6