Loading...
Loading...
Loading...
A highway toll charges a fixed rate for every wheel. Bikes always have 2 wheels and cars 4; a truck tells its own wheel count.
Write a class Vehicle with private fields type, regNo and wheels, a constructor and int toll(int rate). Write Bike, Car and Truck that extend it; Bike and Car pass a fixed type and wheel count with super(...).
bike REG, car REG or truck REG wheels.REG TYPE wheels Rs. toll with TYPE as BIKE, CAR or TRUCK, then TOTAL Rs. sum.Example
Input
20 3 bike KA01AB1234 car MH12XY0001 truck TN09TR7788 10
Output
KA01AB1234 BIKE 2 wheels Rs. 40 MH12XY0001 CAR 4 wheels Rs. 80 TN09TR7788 TRUCK 10 wheels Rs. 200 TOTAL Rs. 320
2, 4 and 10 wheels at Rs. 20 each.
Try the problem first. Open one hint at a time.
Bike(String regNo) can call super("BIKE", regNo, 2): the child fixes the values the parent stores.
Truck passes the wheel count it was given.
toll(rate) and the line printing are written once, in Vehicle.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor