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 8602017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:58:44+00:00 2026-06-12T01:58:44+00:00

I am very new to Java, and relatively new to programming. I have 3

  • 0

I am very new to Java, and relatively new to programming. I have 3 classes, that are connected.

Class 1: Flight

public class Flight {

    private int flightNumber;
    Passenger passenger1 = null; // two objects?
    Passenger passenger2 = null;
    private int confirmedPassengers = 0;
    Passenger bagsChecked;
    //private boolean bagsLoaded;


    public Flight(int fn, int cf){
        flightNumber = fn;
        //passenger1 = p1;
        //passenger2 = p2;
        confirmedPassengers = cf;
        //bagsChecked = bc;

    }


        public boolean addPassenger(Passenger p){
            if (confirmedPassengers == 0){
                passenger1= p;
                confirmedPassengers+=1;         
                System.out.println("P1 has been added.");
                return true;
            }   

            if (confirmedPassengers == 1){
                passenger2 = p;
                confirmedPassengers+=1;
                System.out.println("P2 has been added");
                return true;
            }

                else{
                    System.out.println("This passenger was not added because the capacity is full.");
                    return false;

                }
        }

    }

Class 2: Passenger

public class Passenger {

    private String name;
    Flight flight;
    private int bagsChecked;
    private String confirmationNumber;


    public Passenger(String n, Flight f, int b, String cn){
        name = n;
        flight = f;
        bagsChecked = b;
        confirmationNumber = cn;
    }

    public boolean hasConfirmation(){
        if (confirmationNumber != null) {
            return true;
        }

        else{
            return false;

        }

    }

}

Class 3: Kiosk:

public class Kiosk {
    private int kioskNumber;

    public Kiosk (int k){
        kioskNumber = k;

    }


    public void checkIn(Passenger p){


        if (p.hasConfirmation() == true) {

            addPassenger(p); // trying to add Passenger here
            System.out.println("Passenger " + p.getName() + ""+ "added in at Kiosk1 ");


        }


    }
}

I am trying to add a Passenger to Flight when the passenger checks in at Kiosk. How can I use the addPassenger method in Flight to add Passenger to Kiosk?

  • 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-12T01:58:45+00:00Added an answer on June 12, 2026 at 1:58 am

    In Kiosk.checkIn():

    p.flight.addPassenger(p);
    

    A few recommendations:

    When you have a collection of things (like passanger1 and passanger2) you might want to use an array or better yet some form of collection like ArrayList:

    ArrayList<Passanger> passangers = new ArrayList<Passanger>(2);
    
    passangers.add(p);
    System.out.println(passangers.size());
    

    Also public data members are not very nice. Create setters and getters where you need them, so the code above whould rather look like this (after implementing Passanger.getFlight():

    p.getFlight().addPassenger(p);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to Java. Here is my code: public class funk { int
I am very new to Android development and Java. Have read around but I'm
I'm relatively new to java (specifically swing) and have recently been making some fairly
Java lets you create an entirely new subtype of Throwable , e.g: public class
I'm very new to Java programming, and this is actually part of a problem
I'm very new to Java programming language so this is probably dumb question but
Hi i'm relatively new to java programming. The following program i've written seems to
I am relatively new Java developer that's been thrown in the deep end, my
I have a Java app that fetches a relatively small .zip file using a
I'm very new in Java and I have a small question. I believe it

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.