Loading...
Loading...
A delivery app takes food orders, grocery orders and pickup orders. The checkout code must see only one Order type. Food and grocery are delivered and share a customer, an amount, a distance and a fixed bill format; pickup shares nothing with them.
Write an interface Order (String summary(), int total()), an abstract class Delivered implements Order with the shared fields, a final total() = amount + deliveryFee() and a final summary(). Food: Rs. 20 + Rs. 5 per km, free when the amount is 500 or more. Grocery: Rs. 30, free when the amount is 800 or more. Pickup implements Order directly: 5% off (integer maths), no delivery.
food NAME amount km, grocery NAME amount km or pickup NAME amount.NAME TYPE amount + fee = total (TYPE FOOD or GROCERY). Pickup: NAME PICKUP amount - off = total. Then REVENUE x.Example
Input
3 food Aarav 400 4 grocery Priya 650 2 pickup Rohan 300
Output
Aarav FOOD 400 + 40 = 440 Priya GROCERY 650 + 30 = 680 Rohan PICKUP 300 - 15 = 285 REVENUE 1405
Food: 20 + 4 × 5 = 40. Grocery under 800 pays 30. Pickup saves 300 × 5 / 100 = 15.
Try the problem first. Open one hint at a time.
The interface is what main uses; the abstract base class holds what only the two delivered types share.
Delivered implements total() and summary() and leaves deliveryFee() and type() abstract.
Pickup writes its own total() and summary(); it does not extend Delivered.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor