This program calculates change for a purchase.
- Static variables keep track of item price, amount tendered, and remaining change.
- Methods help isolate functional components.
- Double types defaulted to many decimal places when performing operations, which provided too fine of a precision in regards to currency with two decimal places.
- The
DecimalFormatobject provided a way to define the decimal places required:DecimalFormat df = new DecimalFormat("#.00") - Converting the DecimalFormat back to Double helped continue with the calculation:
remaining = Double.valueOf(df.format(remaining))
- JavaSE-1.8
- Eclipse IDE
- Andy Cary (@acary)