Code Kata Report

diff -r 0699b1f45325 -r 2b6977b72541 src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 11:32:17 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 11:47:46 2012 -0500 @@ -15,10 +15,13 @@ @Test public void checkAmount0ShouldPrintZero() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(0)).toString(), is(equalTo("Zero and 00/100 dollars"))); } - /* + @Test - public void checkAmount1centShouldPrintZeroAndOneCent - */ + public void checkAmount1centShouldPrintZeroAndOneCent() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(0.01)).toString(), is(equalTo("Zero and 01/100 dollars"))); + } + + } diff -r 0699b1f45325 -r 2b6977b72541 src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 11:32:17 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 11:47:46 2012 -0500 @@ -1,17 +1,20 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; public class SpellOutCheckAmount { - BigDecimal amount; + long dollarAmount; + short centsAmount; SpellOutCheckAmount(BigDecimal value) { - amount = value; + dollarAmount = value.longValue(); + centsAmount = (short) Math.round((value.doubleValue() - + dollarAmount) * 100); } @Override public String toString() { - return "Zero and 00/100 dollars"; + return String.format("Zero and %02d/100 dollars", centsAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 2b6977b72541 -r f8066fb7ad6c src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 11:47:46 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 11:56:17 2012 -0500 @@ -21,7 +21,17 @@ @Test public void checkAmount1centShouldPrintZeroAndOneCent() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(0.01)).toString(), is(equalTo("Zero and 01/100 dollars"))); } + @Test + public void checkAmount20centsShouldPrintZeroAnd20Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(0.20)).toString(), is(equalTo("Zero and 20/100 dollars"))); + } + + @Test + public void checkAmount20Point7CentsShouldPrintZeroAnd20Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(0.207)).toString(), is(equalTo("Zero and 20/100 dollars"))); + } + } diff -r 2b6977b72541 -r f8066fb7ad6c src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 11:47:46 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 11:56:17 2012 -0500 @@ -1,20 +1,20 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; public class SpellOutCheckAmount { long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { dollarAmount = value.longValue(); - centsAmount = (short) Math.round((value.doubleValue() - + centsAmount = (short) Math.floor((value.doubleValue() - dollarAmount) * 100); } @Override public String toString() { return String.format("Zero and %02d/100 dollars", centsAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r f8066fb7ad6c -r 8bd754460be0 src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 11:56:17 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 12:02:04 2012 -0500 @@ -30,8 +30,11 @@ @Test public void checkAmount20Point7CentsShouldPrintZeroAnd20Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(0.207)).toString(), is(equalTo("Zero and 20/100 dollars"))); } - - + + @Test + public void checkAmount1DollarShouldPrintOneAnd00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(1.00)).toString(), is(equalTo("One and 00/100 dollars"))); + } } diff -r f8066fb7ad6c -r 8bd754460be0 src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 11:56:17 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 12:02:04 2012 -0500 @@ -1,20 +1,24 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; public class SpellOutCheckAmount { long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { dollarAmount = value.longValue(); centsAmount = (short) Math.floor((value.doubleValue() - dollarAmount) * 100); } @Override public String toString() { - return String.format("Zero and %02d/100 dollars", centsAmount); + String dollarString = "Zero"; + if (dollarAmount == 1) { + dollarString = "One"; + } + return String.format(dollarString + " and %02d/100 dollars", centsAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 8bd754460be0 -r aac55f30d7dd src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 12:02:04 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 12:52:25 2012 -0500 @@ -28,13 +28,28 @@ assertThat(new SpellOutCheckAmount(new BigDecimal(0.20)).toString(), is(equalTo("Zero and 20/100 dollars"))); } @Test public void checkAmount20Point7CentsShouldPrintZeroAnd20Cents() throws Exception { - assertThat(new SpellOutCheckAmount(new BigDecimal(0.207)).toString(), is(equalTo("Zero and 20/100 dollars"))); + assertThat(new SpellOutCheckAmount(new BigDecimal(0.207)).toString(), is(equalTo("Zero and 21/100 dollars"))); } @Test public void checkAmount1DollarShouldPrintOneAnd00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(1.00)).toString(), is(equalTo("One and 00/100 dollars"))); } + + @Test + public void checkAmount1DollarShouldPrintOneAnd01Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(1.01)).toString(), is(equalTo("One and 01/100 dollars"))); + } + + @Test + public void checkAmount2DollarShouldPrintOneAnd01Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(2.01)).toString(), is(equalTo("Two and 01/100 dollars"))); + } + +// @Test +// public void checkAmount10DollarShowPrintTenAnd00Cents() throws Exception { +// assertThat(new SpellOutCheckAmount(new BigDecimal(10.00)).toString(), is(equalTo("Ten and 00/100 dollars"))); +// } } diff -r 8bd754460be0 -r aac55f30d7dd src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 12:02:04 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 12:52:25 2012 -0500 @@ -1,24 +1,30 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; +import java.math.MathContext; public class SpellOutCheckAmount { long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { - dollarAmount = value.longValue(); - centsAmount = (short) Math.floor((value.doubleValue() - - dollarAmount) * 100); + BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); + + dollarAmount = formattedValue.longValue(); + + centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount == 1) { dollarString = "One"; + } else if (dollarAmount == 2) { + dollarString = "Two"; } return String.format(dollarString + " and %02d/100 dollars", centsAmount); +// return dollarString + " and " + centsAmount + "/100 dollars"; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r aac55f30d7dd -r 9451ce44e938 src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 12:52:25 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:04:01 2012 -0500 @@ -46,10 +46,16 @@ @Test public void checkAmount2DollarShouldPrintOneAnd01Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(2.01)).toString(), is(equalTo("Two and 01/100 dollars"))); } + @Test + public void checkAmount10DollarShowPrintTenAnd00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(10.00)).toString(), is(equalTo("Ten and 00/100 dollars"))); + } + // @Test -// public void checkAmount10DollarShowPrintTenAnd00Cents() throws Exception { -// assertThat(new SpellOutCheckAmount(new BigDecimal(10.00)).toString(), is(equalTo("Ten and 00/100 dollars"))); +// public void returnThreeDollarsWith99Cents() throws Exception { +// assertThat(new SpellOutCheckAmount(new BigDecimal(3.9939999)).toString(), is(equalTo("Three and 99/100 dollars"))); +// // } } diff -r aac55f30d7dd -r 9451ce44e938 src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 12:52:25 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:04:01 2012 -0500 @@ -1,30 +1,47 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; +import java.util.HashMap; +import java.util.Map; public class SpellOutCheckAmount { + + Map<Long, String> dollarValues = buildDollarValueMap(); long dollarAmount; short centsAmount; + SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; - if (dollarAmount == 1) { - dollarString = "One"; - } else if (dollarAmount == 2) { - dollarString = "Two"; - } + if (dollarAmount > 0) { + dollarString = getDollarString(dollarAmount); + } return String.format(dollarString + " and %02d/100 dollars", centsAmount); -// return dollarString + " and " + centsAmount + "/100 dollars"; + } + + private Map<Long, String> buildDollarValueMap() { + Map<Long, String> dollarValueMap = new HashMap<Long, String>(); + dollarValueMap.put(1l, "One"); + dollarValueMap.put(2l, "Two"); +// dollarValueMap.put(3l, "Three"); +// dollarValueMap.put(4l, "Four"); +// dollarValueMap.put(5l, "Five"); + dollarValueMap.put(10l, "Ten"); + + return dollarValueMap; + } + private String getDollarString(long dollarAmount) { + return dollarValues.get(dollarAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 9451ce44e938 -r 1556733d3e8c src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:04:01 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:07:31 2012 -0500 @@ -51,11 +51,16 @@ @Test public void checkAmount10DollarShowPrintTenAnd00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(10.00)).toString(), is(equalTo("Ten and 00/100 dollars"))); } -// @Test -// public void returnThreeDollarsWith99Cents() throws Exception { -// assertThat(new SpellOutCheckAmount(new BigDecimal(3.9939999)).toString(), is(equalTo("Three and 99/100 dollars"))); -// -// } + @Test + public void returnThreeDollarsWith99Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(3.9939999)).toString(), is(equalTo("Three and 99/100 dollars"))); + } + /* + @Test + public void returnFourDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(4.00)).toString(), is(equalTo("Four and 00/100 dollars"))); + } + */ } diff -r 9451ce44e938 -r 1556733d3e8c src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:04:01 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:07:31 2012 -0500 @@ -1,47 +1,47 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { Map<Long, String> dollarValues = buildDollarValueMap(); long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); -// dollarValueMap.put(3l, "Three"); + dollarValueMap.put(3l, "Three"); // dollarValueMap.put(4l, "Four"); // dollarValueMap.put(5l, "Five"); dollarValueMap.put(10l, "Ten"); return dollarValueMap; } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 1556733d3e8c -r bb4a99abec6f src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:07:31 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:18:11 2012 -0500 @@ -55,12 +55,17 @@ @Test public void returnThreeDollarsWith99Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(3.9939999)).toString(), is(equalTo("Three and 99/100 dollars"))); } - /* + @Test public void returnFourDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(4.00)).toString(), is(equalTo("Four and 00/100 dollars"))); } - */ + +// @Test +// public void returnFiveDollarsWith00Cents() throws Exception { +// assertThat(new SpellOutCheckAmount(new BigDecimal(5.00)).toString(), is(equalTo("Five and 00/100 dollars"))); +// } + } diff -r 1556733d3e8c -r bb4a99abec6f src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:07:31 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:18:11 2012 -0500 @@ -1,47 +1,47 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { Map<Long, String> dollarValues = buildDollarValueMap(); long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); -// dollarValueMap.put(4l, "Four"); + dollarValueMap.put(4l, "Four"); // dollarValueMap.put(5l, "Five"); dollarValueMap.put(10l, "Ten"); return dollarValueMap; } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r bb4a99abec6f -r f535bf293e8b src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:18:11 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:19:11 2012 -0500 @@ -61,11 +61,11 @@ @Test public void returnFourDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(4.00)).toString(), is(equalTo("Four and 00/100 dollars"))); } -// @Test -// public void returnFiveDollarsWith00Cents() throws Exception { -// assertThat(new SpellOutCheckAmount(new BigDecimal(5.00)).toString(), is(equalTo("Five and 00/100 dollars"))); -// } + @Test + public void returnFiveDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(5.00)).toString(), is(equalTo("Five and 00/100 dollars"))); + } } diff -r bb4a99abec6f -r f535bf293e8b src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:18:11 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:19:11 2012 -0500 @@ -1,47 +1,47 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { Map<Long, String> dollarValues = buildDollarValueMap(); long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); dollarValueMap.put(4l, "Four"); -// dollarValueMap.put(5l, "Five"); + dollarValueMap.put(5l, "Five"); dollarValueMap.put(10l, "Ten"); return dollarValueMap; } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r f535bf293e8b -r 0ffad885a10e src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:19:11 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:22:04 2012 -0500 @@ -66,6 +66,25 @@ @Test public void returnFiveDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(5.00)).toString(), is(equalTo("Five and 00/100 dollars"))); } + @Test + public void returnSixDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(6.00)).toString(), is(equalTo("Six and 00/100 dollars"))); + } + + @Test + public void returnSevenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(7.00)).toString(), is(equalTo("Seven and 00/100 dollars"))); + } + + @Test + public void returnEightDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(8.00)).toString(), is(equalTo("Eight and 00/100 dollars"))); + } + + @Test + public void returnNineDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(9.00)).toString(), is(equalTo("Nine and 00/100 dollars"))); + } } diff -r f535bf293e8b -r 0ffad885a10e src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:19:11 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:22:04 2012 -0500 @@ -1,47 +1,51 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { Map<Long, String> dollarValues = buildDollarValueMap(); long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); dollarValueMap.put(4l, "Four"); dollarValueMap.put(5l, "Five"); + dollarValueMap.put(6l, "Six"); + dollarValueMap.put(7l, "Seven"); + dollarValueMap.put(8l, "Eight"); + dollarValueMap.put(9l, "Nine"); dollarValueMap.put(10l, "Ten"); return dollarValueMap; } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 0ffad885a10e -r b65bf22d75c0 src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:22:04 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:24:11 2012 -0500 @@ -85,6 +85,11 @@ @Test public void returnNineDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(9.00)).toString(), is(equalTo("Nine and 00/100 dollars"))); } + + @Test + public void returnElevenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(11.00)).toString(), is(equalTo("Eleven and 00/100 dollars"))); + } } diff -r 0ffad885a10e -r b65bf22d75c0 src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:22:04 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:24:11 2012 -0500 @@ -1,51 +1,52 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { Map<Long, String> dollarValues = buildDollarValueMap(); long dollarAmount; short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); dollarValueMap.put(4l, "Four"); dollarValueMap.put(5l, "Five"); dollarValueMap.put(6l, "Six"); dollarValueMap.put(7l, "Seven"); dollarValueMap.put(8l, "Eight"); dollarValueMap.put(9l, "Nine"); dollarValueMap.put(10l, "Ten"); + dollarValueMap.put(11l, "Eleven"); return dollarValueMap; } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r b65bf22d75c0 -r 83cfede7dc5e src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:24:11 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:28:07 2012 -0500 @@ -90,6 +90,21 @@ @Test public void returnElevenDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(11.00)).toString(), is(equalTo("Eleven and 00/100 dollars"))); } + + @Test + public void returnTwelveDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(12.00)).toString(), is(equalTo("Twelve and 00/100 dollars"))); + } + + @Test + public void returnThirteenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(13.00)).toString(), is(equalTo("Thirteen and 00/100 dollars"))); + } +// +// @Test +// public void returnFourteenDollarsWith00Cents() throws Exception { +// assertThat(new SpellOutCheckAmount(new BigDecimal(14.00)).toString(), is(equalTo("Fourteen and 00/100 dollars"))); +// } } diff -r b65bf22d75c0 -r 83cfede7dc5e src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:24:11 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:28:07 2012 -0500 @@ -1,52 +1,56 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { - Map<Long, String> dollarValues = buildDollarValueMap(); - long dollarAmount; - short centsAmount; + private static Map<Long, String> dollarValues = buildDollarValueMap(); + private long dollarAmount; + private short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } + + private String getDollarString(long dollarAmount) { + return dollarValues.get(dollarAmount); + } - private Map<Long, String> buildDollarValueMap() { + private static Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); dollarValueMap.put(4l, "Four"); dollarValueMap.put(5l, "Five"); dollarValueMap.put(6l, "Six"); dollarValueMap.put(7l, "Seven"); dollarValueMap.put(8l, "Eight"); dollarValueMap.put(9l, "Nine"); dollarValueMap.put(10l, "Ten"); dollarValueMap.put(11l, "Eleven"); + dollarValueMap.put(12l, "Twelve"); + dollarValueMap.put(13l, "Thirteen"); return dollarValueMap; } - private String getDollarString(long dollarAmount) { - return dollarValues.get(dollarAmount); - } + } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 83cfede7dc5e -r fb9c4735190b src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:28:07 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:34:45 2012 -0500 @@ -100,11 +100,31 @@ @Test public void returnThirteenDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(13.00)).toString(), is(equalTo("Thirteen and 00/100 dollars"))); } -// -// @Test -// public void returnFourteenDollarsWith00Cents() throws Exception { -// assertThat(new SpellOutCheckAmount(new BigDecimal(14.00)).toString(), is(equalTo("Fourteen and 00/100 dollars"))); -// } + + @Test + public void returnFourteenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(14.00)).toString(), is(equalTo("Fourteen and 00/100 dollars"))); + } + @Test + public void returnFifteenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(15.00)).toString(), is(equalTo("Fifteen and 00/100 dollars"))); + } + @Test + public void returnSixteenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(16.00)).toString(), is(equalTo("Sixteen and 00/100 dollars"))); + } + @Test + public void returnSeventeenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(17.00)).toString(), is(equalTo("Seventeen and 00/100 dollars"))); + } + @Test + public void returnEighteenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(18.00)).toString(), is(equalTo("Eighteen and 00/100 dollars"))); + } + @Test + public void returnNineteenDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(19.00)).toString(), is(equalTo("Nineteen and 00/100 dollars"))); + } } diff -r 83cfede7dc5e -r fb9c4735190b src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:28:07 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:34:45 2012 -0500 @@ -1,56 +1,63 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { private static Map<Long, String> dollarValues = buildDollarValueMap(); private long dollarAmount; private short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } private static Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); dollarValueMap.put(4l, "Four"); dollarValueMap.put(5l, "Five"); dollarValueMap.put(6l, "Six"); dollarValueMap.put(7l, "Seven"); dollarValueMap.put(8l, "Eight"); dollarValueMap.put(9l, "Nine"); dollarValueMap.put(10l, "Ten"); dollarValueMap.put(11l, "Eleven"); dollarValueMap.put(12l, "Twelve"); dollarValueMap.put(13l, "Thirteen"); + dollarValueMap.put(14l, "Fourteen"); + dollarValueMap.put(15l, "Fifteen"); + dollarValueMap.put(16l, "Sixteen"); + dollarValueMap.put(17l, "Seventeen"); + dollarValueMap.put(18l, "Eighteen"); + dollarValueMap.put(19l, "Nineteen"); + return dollarValueMap; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r fb9c4735190b -r 75beee8666fa src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:34:45 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:36:52 2012 -0500 @@ -125,6 +125,14 @@ } @Test public void returnNineteenDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(19.00)).toString(), is(equalTo("Nineteen and 00/100 dollars"))); } + @Test + public void returnTwentyDollarsWith04Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(20.04)).toString(), is(equalTo("Twenty and 04/100 dollars"))); + } +// @Test +// public void returnTwentyOneDollarsWith00Cents() throws Exception { +// assertThat(new SpellOutCheckAmount(new BigDecimal(21.00)).toString(), is(equalTo("Twenty and 04/100 dollars"))); +// } } diff -r fb9c4735190b -r 75beee8666fa src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:34:45 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:36:52 2012 -0500 @@ -1,63 +1,64 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { private static Map<Long, String> dollarValues = buildDollarValueMap(); private long dollarAmount; private short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } private static Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); dollarValueMap.put(4l, "Four"); dollarValueMap.put(5l, "Five"); dollarValueMap.put(6l, "Six"); dollarValueMap.put(7l, "Seven"); dollarValueMap.put(8l, "Eight"); dollarValueMap.put(9l, "Nine"); dollarValueMap.put(10l, "Ten"); dollarValueMap.put(11l, "Eleven"); dollarValueMap.put(12l, "Twelve"); dollarValueMap.put(13l, "Thirteen"); dollarValueMap.put(14l, "Fourteen"); dollarValueMap.put(15l, "Fifteen"); dollarValueMap.put(16l, "Sixteen"); dollarValueMap.put(17l, "Seventeen"); dollarValueMap.put(18l, "Eighteen"); dollarValueMap.put(19l, "Nineteen"); + dollarValueMap.put(20l, "Twenty"); return dollarValueMap; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 75beee8666fa -r 66cbc66cec75 src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:36:52 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:45:12 2012 -0500 @@ -129,10 +129,16 @@ } @Test public void returnTwentyDollarsWith04Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(20.04)).toString(), is(equalTo("Twenty and 04/100 dollars"))); } -// @Test -// public void returnTwentyOneDollarsWith00Cents() throws Exception { -// assertThat(new SpellOutCheckAmount(new BigDecimal(21.00)).toString(), is(equalTo("Twenty and 04/100 dollars"))); -// } + @Test + public void returnTwentyOneDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(21.00)).toString(), is(equalTo("Twenty-One and 00/100 dollars"))); + } + /* + @Test + public void returnThirtyTwoDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(32.00)).toString(), is(equalTo("Thirty-Two and 00/100 dollars"))); + } + */ } diff -r 75beee8666fa -r 66cbc66cec75 src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:36:52 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:45:12 2012 -0500 @@ -1,64 +1,69 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { private static Map<Long, String> dollarValues = buildDollarValueMap(); private long dollarAmount; private short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = "Zero"; - if (dollarAmount > 0) { + if (dollarAmount > 20) { + long ones = dollarAmount % 10; + dollarString = getDollarString(dollarAmount - ones) +"-"+ getDollarString(ones); + } + else if (dollarAmount > 0) { dollarString = getDollarString(dollarAmount); - } + } + return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private String getDollarString(long dollarAmount) { return dollarValues.get(dollarAmount); } private static Map<Long, String> buildDollarValueMap() { Map<Long, String> dollarValueMap = new HashMap<Long, String>(); dollarValueMap.put(1l, "One"); dollarValueMap.put(2l, "Two"); dollarValueMap.put(3l, "Three"); dollarValueMap.put(4l, "Four"); dollarValueMap.put(5l, "Five"); dollarValueMap.put(6l, "Six"); dollarValueMap.put(7l, "Seven"); dollarValueMap.put(8l, "Eight"); dollarValueMap.put(9l, "Nine"); dollarValueMap.put(10l, "Ten"); dollarValueMap.put(11l, "Eleven"); dollarValueMap.put(12l, "Twelve"); dollarValueMap.put(13l, "Thirteen"); dollarValueMap.put(14l, "Fourteen"); dollarValueMap.put(15l, "Fifteen"); dollarValueMap.put(16l, "Sixteen"); dollarValueMap.put(17l, "Seventeen"); dollarValueMap.put(18l, "Eighteen"); dollarValueMap.put(19l, "Nineteen"); dollarValueMap.put(20l, "Twenty"); return dollarValueMap; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 66cbc66cec75 -r 38e13f7a20ab src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:45:12 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:56:02 2012 -0500 @@ -133,12 +133,17 @@ } @Test public void returnTwentyOneDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(21.00)).toString(), is(equalTo("Twenty-One and 00/100 dollars"))); } - /* + + @Test + public void returnThirtyDollarsWith00Cents() throws Exception { + assertThat(new SpellOutCheckAmount(new BigDecimal(30.00)).toString(), is(equalTo("Thirty and 00/100 dollars"))); + } + @Test public void returnThirtyTwoDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(32.00)).toString(), is(equalTo("Thirty-Two and 00/100 dollars"))); } - */ + } diff -r 66cbc66cec75 -r 38e13f7a20ab src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:45:12 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:56:02 2012 -0500 @@ -1,69 +1,67 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { - private static Map<Long, String> dollarValues = buildDollarValueMap(); + private static Map<Long, String> numericTextValues = buildNumericTextMap(); private long dollarAmount; private short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { - String dollarString = "Zero"; - if (dollarAmount > 20) { + String dollarString = getDollarString(dollarAmount); + if (dollarString == null) { long ones = dollarAmount % 10; dollarString = getDollarString(dollarAmount - ones) +"-"+ getDollarString(ones); - } - else if (dollarAmount > 0) { - dollarString = getDollarString(dollarAmount); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private String getDollarString(long dollarAmount) { - return dollarValues.get(dollarAmount); + return numericTextValues.get(dollarAmount); } - private static Map<Long, String> buildDollarValueMap() { - Map<Long, String> dollarValueMap = new HashMap<Long, String>(); - dollarValueMap.put(1l, "One"); - dollarValueMap.put(2l, "Two"); - dollarValueMap.put(3l, "Three"); - dollarValueMap.put(4l, "Four"); - dollarValueMap.put(5l, "Five"); - dollarValueMap.put(6l, "Six"); - dollarValueMap.put(7l, "Seven"); - dollarValueMap.put(8l, "Eight"); - dollarValueMap.put(9l, "Nine"); - dollarValueMap.put(10l, "Ten"); - dollarValueMap.put(11l, "Eleven"); - dollarValueMap.put(12l, "Twelve"); - dollarValueMap.put(13l, "Thirteen"); - dollarValueMap.put(14l, "Fourteen"); - dollarValueMap.put(15l, "Fifteen"); - dollarValueMap.put(16l, "Sixteen"); - dollarValueMap.put(17l, "Seventeen"); - dollarValueMap.put(18l, "Eighteen"); - dollarValueMap.put(19l, "Nineteen"); - dollarValueMap.put(20l, "Twenty"); + private static Map<Long, String> buildNumericTextMap() { + Map<Long, String> numericTextValueMap = new HashMap<Long, String>(); + numericTextValueMap.put(0l, "Zero"); + numericTextValueMap.put(1l, "One"); + numericTextValueMap.put(2l, "Two"); + numericTextValueMap.put(3l, "Three"); + numericTextValueMap.put(4l, "Four"); + numericTextValueMap.put(5l, "Five"); + numericTextValueMap.put(6l, "Six"); + numericTextValueMap.put(7l, "Seven"); + numericTextValueMap.put(8l, "Eight"); + numericTextValueMap.put(9l, "Nine"); + numericTextValueMap.put(10l, "Ten"); + numericTextValueMap.put(11l, "Eleven"); + numericTextValueMap.put(12l, "Twelve"); + numericTextValueMap.put(13l, "Thirteen"); + numericTextValueMap.put(14l, "Fourteen"); + numericTextValueMap.put(15l, "Fifteen"); + numericTextValueMap.put(16l, "Sixteen"); + numericTextValueMap.put(17l, "Seventeen"); + numericTextValueMap.put(18l, "Eighteen"); + numericTextValueMap.put(19l, "Nineteen"); + numericTextValueMap.put(20l, "Twenty"); + numericTextValueMap.put(30l, "Thirty"); - - return dollarValueMap; + return numericTextValueMap; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 38e13f7a20ab -r bcc299f4112c src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:56:02 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckAmountTest.java Fri Jun 15 13:57:54 2012 -0500 @@ -143,7 +143,6 @@ @Test public void returnThirtyTwoDollarsWith00Cents() throws Exception { assertThat(new SpellOutCheckAmount(new BigDecimal(32.00)).toString(), is(equalTo("Thirty-Two and 00/100 dollars"))); } - } diff -r 38e13f7a20ab -r bcc299f4112c src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:56:02 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheckAmount.java Fri Jun 15 13:57:54 2012 -0500 @@ -1,67 +1,68 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.util.HashMap; import java.util.Map; public class SpellOutCheckAmount { private static Map<Long, String> numericTextValues = buildNumericTextMap(); private long dollarAmount; private short centsAmount; SpellOutCheckAmount(BigDecimal value) { BigDecimal formattedValue = value.setScale(2, BigDecimal.ROUND_HALF_UP); dollarAmount = formattedValue.longValue(); centsAmount = formattedValue.subtract(new BigDecimal(dollarAmount)).multiply(new BigDecimal(100)).shortValue(); } @Override public String toString() { String dollarString = getDollarString(dollarAmount); if (dollarString == null) { long ones = dollarAmount % 10; dollarString = getDollarString(dollarAmount - ones) +"-"+ getDollarString(ones); } return String.format(dollarString + " and %02d/100 dollars", centsAmount); } private String getDollarString(long dollarAmount) { return numericTextValues.get(dollarAmount); } private static Map<Long, String> buildNumericTextMap() { Map<Long, String> numericTextValueMap = new HashMap<Long, String>(); numericTextValueMap.put(0l, "Zero"); numericTextValueMap.put(1l, "One"); numericTextValueMap.put(2l, "Two"); numericTextValueMap.put(3l, "Three"); numericTextValueMap.put(4l, "Four"); numericTextValueMap.put(5l, "Five"); numericTextValueMap.put(6l, "Six"); numericTextValueMap.put(7l, "Seven"); numericTextValueMap.put(8l, "Eight"); numericTextValueMap.put(9l, "Nine"); numericTextValueMap.put(10l, "Ten"); numericTextValueMap.put(11l, "Eleven"); numericTextValueMap.put(12l, "Twelve"); numericTextValueMap.put(13l, "Thirteen"); numericTextValueMap.put(14l, "Fourteen"); numericTextValueMap.put(15l, "Fifteen"); numericTextValueMap.put(16l, "Sixteen"); numericTextValueMap.put(17l, "Seventeen"); numericTextValueMap.put(18l, "Eighteen"); numericTextValueMap.put(19l, "Nineteen"); numericTextValueMap.put(20l, "Twenty"); numericTextValueMap.put(30l, "Thirty"); + numericTextValueMap.put(40l, "Forty"); return numericTextValueMap; } }