Loading...
Loading...
Loading...
A power company bills homes at Rs. 5 a unit and shops at Rs. 8 a unit. Farms get their first 100 units free and pay Rs. 2 a unit after that. Write Connection with String type() and long bill(long units) (Rs. 6 a unit by default) and override them in Home, Shop and Farm.
HOME, SHOP or FARM) and the units used.<TYPE> Rs. <bill> for each connection, then Total Rs. <sum>.Example
Input
3 HOME 120 SHOP 50 FARM 160
Output
HOME Rs. 600 SHOP Rs. 400 FARM Rs. 120 Total Rs. 1120
The farm pays for 160 - 100 = 60 units: Rs. 120.
Try the problem first. Open one hint at a time.
Only the rate rule changes per type, so each child overrides bill.
For a farm: units <= 100 ? 0 : (units - 100) * 2.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor