========================
This is one of the common programming question asked in interview qualification rounds.
Complete Test Driven Development(TDD) is followed to develop this program. It is good practice to follow TDD while writing any application.
Have a look at unit tests for this program.