Loading...
Loading...
Loading...
A group books seats on one train under one PNR. The first ticket is entered in full; every other ticket is a copy of it with a new passenger and seat. Write Ticket with a copy constructor and print all the tickets.
PNR <pnr> | <train> | <passenger> | seat <seat>.Example
Input
12627 Karnataka Exp 4521836790 Aarav 32 2 Priya 33 Rohan 34
Output
PNR 4521836790 | 12627 Karnataka Exp | Aarav | seat 32 PNR 4521836790 | 12627 Karnataka Exp | Priya | seat 33 PNR 4521836790 | 12627 Karnataka Exp | Rohan | seat 34
Each copy keeps the PNR and train and changes only the passenger and seat.
Try the problem first. Open one hint at a time.
Ticket(Ticket other) copies all four fields; this(other.pnr, other.train, other.passenger, other.seat) does it in one line.
Read the train with nextLine() first, then the rest with next() and nextInt().
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor