Sunday, March 24, 2013

Proposal for a Bill Splitter Programming Kata


You may have noticed that I mentioned several programming exercises, or katas, within this blog. I practiced these katas several times to improve my skills as a programmer and work on some of my weaknesses. Over the last week, I have been thinking about a potential project I could work on outside of my full time job. Instead, I came up with an idea for a new programming kata:

Bill Splitter Kata

  1. Part 1: A group of friends has a small issue. They eat out a lot together. However, splitting the bill at the end of the meal always takes a long time and, in the end, some folks end up overpaying, while others get away with not paying their fair share. The group has asked you to develop a small application that would allow them to split the bill fairly. One person will be appointed to use the application at the end of every meal to enter the bill's data and read off the results to the rest of the group.
    • A function header you can use:
      • []splitTheBill(foodCost, tax, tipPercent, []foodCostPerPerson)
    • Sample
      • input: splitTheBill(100, 10, 20, 30, 10, 45, 15)
      • output: 39 13 58.5 19.5
      • Note: the nth value in the output is the amount of money owed by the nth person in the input
  2. Part 2: the group really likes your progress in part 1, but finds the implementation lacking in features. A member suggests that the application should include lazy calculation. She suggests that for every person whose food cost is entered as 0, the remaining bill shall be split evenly. Implement this functionality.
    • input: splitTheBill(100, 10, 20, 0, 0, 45, 0)
    • output: 23.83 23.83 58.5 23.83
  3. Part 3: the group was using the application to split their bill at a restaurant. However, some of the members did not carry any change and did not want to use a credit card to pay for their food. Add an option for rounding each person's share to the nearest dollar, while still covering the bill.
    • header: []splitTheBill(foodCost, tax, tipPercent,  round, []foodCostPerPerson)
    • input: splitTheBill(100, 10, 20, true, 0, 0, 45, 0)
    • output: 29 29 58 29
    • Note: make sure that those who are paying for an equal amount of the bill end up paying the correct amount. i.e., 29 28 59 29 would not be a correct output for the sample input, even though the bill is fully covered

Feel free to use any programming language.

03/26/2013 Update:

The kata has been updated to be easier to read.

03/26/2013 Update:

I have completed the kata. Parts 1 and 2 took me under an hour total. Part 3 took me over two hours. I believe that each part can be handled in many different ways. I ended up writing a lot of helper functions for the third part. Test driven and test first development could be of big help in this situation. If you have tried the kata as well, please post your experiences in the comments section.

No comments:

Post a Comment