working code of Programming Assignment2