Question: Consider the following code: Cash Register register = new Cash Register(); register.record Purchase(19.93); register. receive Payment (20, 0, 0, 0, 0); System.out.print(Change: ); System.out.println(register.giveChange()); The
Consider the following code:

Cash Register register = new Cash Register(); register.record Purchase(19.93); register. receive Payment (20, 0, 0, 0, 0); System.out.print("Change: "); System.out.println(register.giveChange()); The code segment prints the total as 0.07000000000000028. Explain why. Give a recom- mendation to improve the code so that users will not be confused.
Step by Step Solution
3.40 Rating (147 Votes )
There are 3 Steps involved in it
The code in question is designed to simulate a cash register transaction The issue arises from the way floatingpoint numbers are handled in computer p... View full answer
Get step-by-step solutions from verified subject matter experts
