Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me with this problem --> Display information of that passenger whose reservation is confirmed in both Plane and Railway . And also how to compare both functions reservation_type and display the answer...?
-------------------------------------------------------------------
complete definition :
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


--------------------------------------------------------------------------------------
code :
--------
C#
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);
    }
}
Posted
Updated 8-Nov-14 22:44pm
v5
Comments
Mehdi Gholam 9-Nov-14 1:36am    
Looks like homework.
A94 9-Nov-14 3:06am    
Yes it is a homework but how should I compare reservation type of both functions...that is the problem...Can you help...
Richard MacCutchan 9-Nov-14 7:14am    
You should have a base reservation type, and then inherit that for the specifics of rail or plane, rather than duplicating all that code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900