finished code for lab 9