Added code for problem 4.7, this time added four cases