Solution for programming assignment2.