solution of ProgrammingAssignment2