Loading...
Loading...
A canteen checks its bills. Prices are typed with exactly two decimals, like 49.99 or 0.10. Write a class Money that stores whole paise in a long, with equals(), hashCode() and a toString() that prints Rs. 62.49. For each bill, add the item prices and compare the total with the amount paid using equals().
Rs. <rupees>.<paise>, then OK when it equals the amount paid, else MISMATCH.Example
Input
3 2 0.10 0.20 0.30 3 49.99 12.50 0.01 62.50 1 10.00 9.99
Output
Rs. 0.30 OK Rs. 62.50 OK Rs. 10.00 MISMATCH
With double, 0.10 + 0.20 would not equal 0.30; in paise, 10 + 20 is exactly 30.
Try the problem first. Open one hint at a time.
Split each price at the dot: rupees before it, paise after it. Long.parseLong turns each part into a number.
Keep the total as a Money and add with a small plus method that returns a new Money.
equals() compares the paise fields with ==, which is exact for whole numbers.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor