Loading...
Loading...
A general ticket costs the base fare. A reserved ticket adds a Rs. 40 reservation charge. A Tatkal ticket is a reserved ticket plus a Tatkal charge of 30% of the base fare (rounded down), but never less than 100 or more than 400.
Build the chain Ticket → ReservedTicket → TatkalTicket (a final class). Each level gives its own int fare() that adds to super.fare(), and its own String kind().
G name base, R name base or T name base.name KIND fare with KIND GENERAL, RESERVED or TATKAL, then TOTAL sum.Example
Input
3 G Asha 120 R Ravi 500 T Meena 500
Output
Asha GENERAL 120 Ravi RESERVED 540 Meena TATKAL 690 TOTAL 1350
Meena pays 500 + 40 + 150.
Try the problem first. Open one hint at a time.
ReservedTicket.fare() is super.fare() + 40; TatkalTicket.fare() is super.fare() + charge.
The Tatkal charge needs the base fare: give Ticket a getBase() getter.
Limit the charge with two if checks, or Math.max(100, Math.min(400, ...)).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor