Add the codes for exercise 3.1