Create two interface Plane and Railway and one class Passenger. Plane interface have method flit_reservation() and Railway interface have method rail_reservation().Passenger class inherits the properties of Plane and Railway and it have data members like name,city, reservation type(confirmed/waiting) and have method display(),do the following operations for this definition (a) Achieving Multiple inheritances. (b) Override all the methods of parent in child class. (c) Display information of that passenger whose reservation is confirmed in both Plane and Railway
import java.util.Scanner; interface Plane { public void flit_reservation(); } interface Railway { public void rail_reservation(); } class Passenger implements Plane,Railway { String name; String city; String reservation_type; public void flit_reservation() { Scanner s=new Scanner(System.in); System.out.println("----------------- PLANE RESERVATION ---------------"); System.out.println("Enter Name :"); name=s.nextLine(); System.out.println("Enter City :"); city=s.next(); System.out.println("Enter Reservation Type(Confirmed/Waiting) :"); reservation_type=s.next(); System.out.println("--------------------------------------------------------------"); } public void rail_reservation() { Scanner s=new Scanner(System.in); System.out.println("----------------- RAIL RESERVATION ---------------"); System.out.println("Enter Name :"); name=s.nextLine(); System.out.println("Enter City :"); city=s.next(); System.out.println("Enter Reservation Type(Confirmed/Waiting) :"); reservation_type=s.next(); System.out.println("--------------------------------------------------------------"); } void display(Passenger ps[]) { for(int i=0;i<ps.length;i++) { if(ps[i].reservation_type=="Confirmed" || ps[i].reservation_type=="confirmed") { System.out.println("Passenger Name :"+ps[i].name); System.out.println("City :"+ps[i].city); System.out.println("Reservation Status :"+ps[i].reservation_type); } } } } class Pro21 { public static void main(String args[]) { Passenger p[]=new Passenger[2]; for(int i=0;i<p.length;i++) { p[i]=new Passenger(); } for(int i=0;i<p.length;i++) { p[i].flit_reservation(); p[i].rail_reservation(); } p[0].display(p); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)