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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:53:31+00:00 2026-06-15T15:53:31+00:00

Hey im using a hashmap of string and flights to create a flight store

  • 0

Hey im using a hashmap of string and flights to create a flight store called planeStore. So then i made another store(Airline store) also using a hashmap. I put the planeStore into the AirlineStore. But i cant get the airlines printing out with the planes.

I thought by putting string airlineName into Airlines constrcutor. And passing in “Plane Name” When creating Airline airline = new Airline(“PlaneName”); that this would work but it hasnt.

here is my code:

Airline

import java.util.HashMap;


public class Airline 
{
    private String airlineName;
    private HashMap<String, PlaneStore> map;

    public Airline(String airlineName)
    {
        this.airlineName = "";
        map = new HashMap<String, PlaneStore>();
    }
    public void add(PlaneStore plane)
    {
        map.put(airlineName, plane);
    }
    public void remove(String flight)
    {
        map.remove(flight);
    }
    public void printPlane()
    {
        System.out.println("\n********Flight List********");
        for (PlaneStore plane: map.values()) {
             //System.out.println(plane);
            // class
            // or:
            System.out.println(airlineName);
            System.out.println(plane.toString());

        }

    }

}

plane.toString is the toString of the PlaneStore:

public String toString() {
        return "PlaneStore [airlineName=" + airlineName + ", planeMap="
                + planeMap + "]";
    }

MainApp

import java.util.Scanner;


public class MainApp 
{
    private Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args)
    {
        new MainApp().start();  
    }

    public void start()
    {
        Airline airline1 = new Airline("AerLingus");
        Airline airline2 = new Airline("Ryan Air");
        PlaneStore planeStore = new PlaneStore("Aer Lingus");
        PlaneStore planeStore2 = new PlaneStore("Ryan Air");

        Flight p1 = new Flight("Aer Lingus","A01", 150.5, 10.5, 500, Flight.AIRPLANETYPE.AIRBUS);
        Flight p2 = new Flight("Aer Lingus","B01", 50.3, 1.5, 91, Flight.AIRPLANETYPE.CORPORATE);
        Flight p3 = new Flight("Aer Lingus","C01", 12.2, -3.1, 56, Flight.AIRPLANETYPE.AIRBUS);


        Flight p4 = new Flight("Ryan Air","D01", 10.5, 1.5, 430, Flight.AIRPLANETYPE.PRIVATE);
        Flight p5 = new Flight("Ryan Air","E01", 0.3, 2.1, 101, Flight.AIRPLANETYPE.CORPORATE);
        Flight p6 = new Flight("Ryan Air","F01", 2.2, -3, 291, Flight.AIRPLANETYPE.AIRBUS);
        planeStore.add(p1);
        planeStore.add(p2);
        planeStore.add(p3);
        planeStore.print();

        airline1.add(planeStore);
        airline1.add(planeStore);
        airline1.add(planeStore);
        airline1.printPlane();

        planeStore2.add(p4);
        planeStore2.add(p5);
        planeStore2.add(p6);

        airline2.add(planeStore2);
        airline2.add(planeStore2);
        airline2.add(planeStore2);
        airline2.printPlane();



    }

}
  • 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-15T15:53:32+00:00Added an answer on June 15, 2026 at 3:53 pm

    Your Airline construtor receives a String argument but you are not assignment the instance variable airlineName of the class Airline to this argument. You are just making airlineName set to “”.

    public Airline(String airlineName)
        {
            this.airlineName = "";
            map = new HashMap<String, PlaneStore>();
        }
    

    you mean:

    public Airline(String airlineName)
            {
                this.airlineName = airlineName;
                map = new HashMap<String, PlaneStore>();
            }
    

    Looking further in your code, it appears that each Airline class will have an map but you only add a key to this map, along with the values PlaneStore. So it appears that you will never have two or more keys for each map on each Airline class. Therefore, there is no point in using map, you can use instead an ArrayList.

    If I understand correctly your objective you can simplify your AirLine class to something like this:

    public class Airline 
    {
        private String airlineName;                // Name of the company
        private ArrayList <PlaneStore> planeStore;
    
        public Airline(String airlineName)
        {
            this.airlineName = airlineName;
            map = new ArrayList<PlaneStore>();
        }
        public void add(PlaneStore plane){ planeStore.add(plane);}
    
    
        public void printPlane()
        {
    
            System.out.println(airlineName);
            System.out.println("\n********Flight List********");
            for (PlaneStore plane: planeStore)
            {
                System.out.println(plane.toString());
            }
    
        }
    

    }

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

Sidebar

Related Questions

Hey I'm a using a Jquery plugin called qTip to create an image rollover
Hey guys, I'm using Twitter's PHP API, called twitterlibphp , and it works well,
Hey i'm using oracle sql to create a database. I im now working on
Hey I am using a NSURL Connection to receive data. [NSURLConnection sendSynchronousRequest: //create request
Hey guys im using the method above like: string = [array componentsJoinedByString:@\n]; this prints
Hey so i've made a text game using the pdCurses library and microsoft opperating
Hey guys, I am using a hash_map to relate strings to one another, with
Hey I'm using a HashMap to keep track of services and service-requests on a
Hey I'm using phonegap databases, and trying to understand why my callback is called
Hey i'm loading an html page using ajax into a string, now i want

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.