Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:43:02+00:00 2026-06-17T07:43:02+00:00

i am working on a small app that mange flights, i have a class

  • 0

i am working on a small app that mange flights, i have a class that build a flight details and class that build the passenger, now, i want to load the passengers onto a flight, how should i do it? do i need to build a higer class that inherit from this two class and make a list of that type of class(i dont think that wise oop ).or should i add a ticket prop in the passenger class that have the flight number, here is my code.

  public class Passenger
{
    public Passenger(string name, int passportNumber)
    {
        this.PassengerName = name;
        this.PassportNumber = passportNumber;
    }

    private string _passengerName;
    public string PassengerName
    {
        get { return _passengerName; }
        set { _passengerName = value; }
    }

    private int _passportNumber;
    public int PassportNumber
    {
        get { return _passportNumber; }
        set { _passportNumber = value; }
    }

 }

public class FlightDetails
{
    public FlightDetails(int flightNumber, string flightDestination, string planmodel)
    {
        this.FlightNumber = flightNumber;
        this.FlightDestination = flightDestination;
        this.PlanModel = planmodel;
    }

    private int _flightNumber;
    public int FlightNumber
    {
        get { return _flightNumber; }
        set { _flightNumber = value; }
    }

    private string _flightDestination;
    public string FlightDestination
    {
        get { return _flightDestination; }
        set { _flightDestination = value; }
    }

    private string _planeModel;
    public string PlanModel
    {
        get { return _planeModel; }
        set { _planeModel = value; }
    }
}
      static void Main(string[] args)
    {
        List<FlightDetails> flightList = new List<FlightDetails>();

        FlightDetails a = new FlightDetails(12,"france","jumbo");///create a flight

        flightList.Add(a);///  load up the flight

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:43:03+00:00Added an answer on June 17, 2026 at 7:43 am

    Here’s a sample code that might work. A flight has one or more passengers, thus has a List of type Passenger. In real-life, a passenger can book multiple flights. If you want the reality, you’ll have to change your model but for this situation it’ll work:

    public class Passenger
    {
        public Passenger(string name, int passportNumber)
        {
            PassengerName = name;
            PassportNumber = passportNumber
        }
    
        public string PassengerName { get; set; }
        public int PassportNumber { get; set; }
    }
    
    public class FlightDetails
    {
        public FlightDetails(int flightNumber, string flightDestination, string planmodel)
        {
            FlightNumber = flightNumber;
            FlightDestination = flightDestination;
            PlanModel = planmodel;
            Passengers = new List<Passengers>();
        }
    
        public int FlightNumber { get; set; }
        public string FlightDestination  { get; set; }
        public string PlanModel { get; set; }
        public List<Passenger> Passengers { get; private set; }
    
        public void AddPassenger(string name, int number)
        {
            int max = 2;
            int passengersNumber = Passengers.Count;
    
            if (passengersNumber < max)
            {
                Passengers.Add(new Passenger(name, number);
            }
        }
    public static void Main(string[] args)
    {
        var flightList = new List<FlightDetails>();
        var passengersList = new List<Passenger>();
    
        //Add passenger-objects to passengers-list
    
        var flightOne = new FlightDetails(12, "France", "Jumbo");
        flightOne.Passengers = passengersList;
    
        flightList.Add(a);
    }
    

    Here’s a better solution to limit the passengers:

    public class FlightDetails
    {
        public FlightDetails(int flightNumber, string flightDestination, string planmodel)
            : this(flightNumber, flightDestination, planmodel, new List<Passenger>())
        {
        }
    
        public FlightDetails(int flightNumber, string flightDestination, string planmodel, List<Passenger> passengers)
        {
            FlightNumber = flightNumber;
            FlightDestination = flightDestination;
            PlanModel = planmodel;
    
            if(passengers.Count > 2)
                //throw exception or error
            else
                _passengers = passengers;
        }
    
        private List<Passenger> _passengers = new List<Passenger>();
    
        public int FlightNumber { get; set; }
        public string FlightDestination  { get; set; }
        public string PlanModel { get; set; }
    
        public IEnumerable<Passenger> Passengers { get { return _passengers; } }
    
        public void AddPassenger(string name, int number)
        {
            int max = 2;
            int passengersNumber = _passengers.Count;
    
            if (passengersNumber < max)
            {
                _passengers.Add(new Passenger(name, number);
            }
        }
    }
    

    Note: this code is written without compiling. But the idea is correct normally. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a small app that uses the Facebook API. What I want
I have a small IPhone app that I am working on and I am
I have a small app I am working on that generates configuration files. Because
I have a small app I have been working on that uses the front
I want to build a small App that will recognize any Bluetooth headset connection
I have a small chat app that I am working on, but got stuck
I used to have a small chat app(which was almost working), that uses PHP,
I’m currently working on a small web app that allows people to search for
I am working on an existing ASP.NET MVC app that started small and has
I have a small app I'm working on where I'm trying to use Django's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.