Loading...
Loading...
A food delivery app adds 5% GST to the food amount and a delivery fee of ₹40, but delivery is free when the food costs ₹499 or more. GST is not charged on the delivery fee.
Write a class Billing whose rules are static final constants (GST_PERCENT, DELIVERY_FEE, FREE_DELIVERY_FROM) and a static method that returns the amount to pay. Change a rule in one place and every bill follows it.
FOOD f GST g DELIVERY d PAY p, where f, g and p have two digits after the decimal point and d is a whole number.Example
Input
3 450 499 1000
Output
FOOD 450.00 GST 22.50 DELIVERY 40 PAY 512.50 FOOD 499.00 GST 24.95 DELIVERY 0 PAY 523.95 FOOD 1000.00 GST 50.00 DELIVERY 0 PAY 1050.00
₹450 still pays delivery; from ₹499 delivery is free.
Try the problem first. Open one hint at a time.
static final makes each rule one shared value that can never be changed while the program runs.
Work in paise to keep the money exact: GST in paise is amount × GST_PERCENT.
Compare with >= for the free-delivery limit.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor