working code programming assignment 2 and 3