finished code for Quiz4 in chapter8