Solution for ProgrammingAssignment2