CHOW #167 – The coin tender kata

The challenge of this week is a very famous Code Kata called as Coin Tender. This kata assumes very important and have subtle association with the Post

Hence I suggest you to first attempt to practice this Code Kata before reading the post. Then again return to this Code Kata. 

Specification

Well, the requirement is, creating a virtual coin-tender, to dispense Penny, Nickel, Dime and Quarter in exchange of the given input.

Where :

P -> Penny; 
N -> Nickel (5 Penny);
D -> Dime (5 Nickel or 10 Penny);
Q -> Quarter (25 Penny);

So, 

if you input 7 to the coin tender it should respond with NPP. 

If you input 42 the response should be QDNPP.

Expectation

The code satisfies the first two test cases. The given code is deliberately un-refactored. 

The challenge is; refactor the code and extend the code to dispense Dime and Quarter.

Enjoy observing how your code is transformed each time you introduce a test.

https://gist.github.com/krsmanian1972/64699016325e6e6cd64e3e3f32cebf4b

https://gist.github.com/krsmanian1972/0ed4713a2ffc20875e6bdfb27b8a59f1

Looking forward to your clean code and observations.

Thanks.

Raja Subramanian

What do you think?

Leave a Reply

What to read next