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

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

1 Expert Approved Answer
Step: 1 Unlock

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

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!