tdd-java-demo
tdd java demo with micro-commits
git clone https://9o.is/git/tdd-java-demo.git
commit fe833bd829a5b9859f93c393f5c4b3a5bb73dd37 parent 77cfb37ee9427a576eec82ca02d9a54e896f7c0b Author: Jul <jul@9o.is> Date: Wed, 31 Mar 2021 16:51:58 +0800 extract method getTotal (that calculates total) Diffstat:
| M | src/main/java/takehome/Runner.java | | | 11 | ++++++++--- |
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/main/java/takehome/Runner.java b/src/main/java/takehome/Runner.java @@ -29,14 +29,19 @@ public class Runner { amounts.put(item, amount); } + double total = getTotal(amounts); + + DecimalFormat df = new DecimalFormat("0.00"); + out.println("Total: $" + df.format(total)); + } + + private double getTotal(Map<Item, Integer> amounts) { double total = 0; for (Item item : amounts.keySet()) { int amount = amounts.get(item); total += item.getTotal(amount); } - - DecimalFormat df = new DecimalFormat("0.00"); - out.println("Total: $" + df.format(total)); + return total; } private int getItemAmount(Item item) {