Added code as per the assignment.