Loading...
Loading...
Every order pays subtotal + delivery fee − discount. A normal order pays a Rs. 40 fee below Rs. 300 and nothing from Rs. 300; it gets no discount. A Prime order pays no fee and gets 10% off (rounded down) from Rs. 500. A student order pays half the normal fee (use super) and gets Rs. 50 off from Rs. 200. Write Order with deliveryFee(), discount() and a payable() that combines them.
NORMAL, PRIME or STUDENT) and the subtotal.<TYPE> fee <f> discount <d> pay <p> for each order, then Collected <sum of pay>.Example
Input
3 NORMAL 250 PRIME 800 STUDENT 220
Output
NORMAL fee 40 discount 0 pay 290 PRIME fee 0 discount 80 pay 720 STUDENT fee 20 discount 50 pay 190 Collected 1200
Student: half of the Rs. 40 fee = 20, and 50 off: 220 + 20 − 50 = 190.
Try the problem first. Open one hint at a time.
payable() is written once in Order: subtotal + deliveryFee() - discount().
Student extends Order and its fee is super.deliveryFee() / 2.
Each override answers one question only: the fee or the discount.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor