Solution to programming Assignment 2