Loading...
Loading...
Loading...
A food app has a "Repeat order" button. It copies the last order, and the user may change some quantities before paying. The last order and its bill must not change. Write Item and Order so that the copy is deep, then print both orders.
Last order: <name> x<qty>, ... = Rs <total> and Reorder: <name> x<qty>, ... = Rs <total>.Example
Input
2 Dosa 2 80 Coffee 2 30 1 1 3
Output
Last order: Dosa x2, Coffee x2 = Rs 220 Reorder: Dosa x3, Coffee x2 = Rs 300
One more dosa in the reorder only: 3 × 80 + 2 × 30 = 300.
Try the problem first. Open one hint at a time.
items.clone() makes a new array of the same Item objects: still shallow.
Make a new Item[], then fill each slot with new Item(other.items[i]).
One line can cost 10^5 × 10^5 = 10^10 rupees, far above the int limit, so multiply and add in long.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor