Loading...
Loading...
Loading...
The electricity board bills home, shop and factory connections. Every bill is units × rate + a fixed charge, but the rate and the fixed charge depend on the type.
Write an abstract class Connection with a constructor that stores units, abstract int rate(), abstract int fixedCharge() and a final int bill(). Write Home (Rs. 5 per unit, no fixed charge), Shop (Rs. 8, Rs. 100) and Factory (Rs. 6, Rs. 500).
home u, shop u or factory u.TYPE units -> Rs. bill (TYPE in capitals), then TOTAL Rs. x.Example
Input
3 home 200 shop 200 factory 200
Output
HOME 200 -> Rs. 1000 SHOP 200 -> Rs. 1700 FACTORY 200 -> Rs. 1700 TOTAL Rs. 4400
1000, 1600 + 100 and 1200 + 500.
Try the problem first. Open one hint at a time.
The formula lives only in bill() in the parent; children give just two numbers.
Each child constructor passes units up with super(units).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor