Loading...
Loading...
A food app takes one order from one restaurant. The restaurant creates its menu dishes; the order creates its own items, each pointing at a menu dish; payment is delegated to a UPI or card object; the order moves PLACED → PAID → DELIVERED.
Use enum OrderStatus { PLACED, PAID, DELIVERED }, an interface PaymentMethod (boolean pay(int amount), String label()), Restaurant (composes Dishes), and Order (composes OrderItems).
dish NAME PRICE, add NAME QTY, pay upi|card, deliver or bill. UPI refuses a payment above Rs. 2000.dish prints nothing. add: ORDER LOCKED (not PLACED), NO DISH NAME, BAD QTY (qty < 1), or ADDED QTY x NAME. pay: ALREADY PAID, EMPTY ORDER, PAID T BY LABEL or DECLINED T BY LABEL. deliver: NOT PAID, DELIVERED or ALREADY DELIVERED. bill: one line per item QTY x NAME = Rs. A, then TOTAL T STATUS S.Example 1
Input
1000 9 dish Dosa 80 dish Coffee 30 add Dosa 2 add Pizza 1 add Coffee 0 deliver pay upi add Coffee 1 bill
Output
ADDED 2 x Dosa NO DISH Pizza BAD QTY NOT PAID PAID 160 BY UPI ORDER LOCKED 2 x Dosa = Rs. 160 TOTAL 160 STATUS PAID
Pizza is not on the menu, quantity 0 is refused, and after paying the order is locked.
Example 2
Input
500 6 dish Thali 300 add Thali 3 pay card pay upi deliver deliver
Output
ADDED 3 x Thali DECLINED 900 BY CARD PAID 900 BY UPI DELIVERED ALREADY DELIVERED
The card limit 500 is too low for 900; UPI accepts it.
Try the problem first. Open one hint at a time.
Every command first checks the status: an if on status != OrderStatus.PLACED blocks changes after payment.
Restaurant.find(name) returns the menu Dish or null; OrderItem keeps that Dish reference and a quantity.
pay builds or picks the payment object and only changes the status when method.pay(total) returns true.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor