Monday, April 9, 2012

Potter Kata

Today, I have been working on the Potter Kata. Below are my notes:

  • I was not able to complete the kata because I did not allocate enough time to it today.
  • I have created a nice regular expression for currency using this regular expression testerThe regular expression encompasses strings such as $0.00, $0.37, $1.42, and $12313.99. However, it  does not cover $00.00, $00.0, and a few others, just as I intended. I have used this source to come up with the exact regex I was looking for:
\$(([1-9]{1}[0-9]*)|([0-9]))\.[0-9]{2}
  • The following two lines of Java code can print a double in the above format. It requires an import of the java.text.DecimalFormat package.
DecimalFormat df = new DecimalFormat("#.##");
System.out.printf("$%.2f\n", Double.valueOf(df.format(13.37)));
// Output: $13.37
  • I will complete the kata in the next few days.

No comments:

Post a Comment