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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:29:34+00:00 2026-06-15T17:29:34+00:00

Hey im trying to make a hashMap store for planes. But when i add,

  • 0

Hey im trying to make a hashMap store for planes. But when i add, it will only print out one flight. Can anyone help me with this.
Here is my code:

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 aerLingus = new Airline("AerLingus");
        PlaneStore planeStore = new PlaneStore("Aer Lingus");

        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.addFlight("",p1);
        planeStore.addFlight("",p2);
        planeStore.addFlight("",p3);
        planeStore.print();

        aerLingus.add(planeStore);
        aerLingus.add(planeStore);
        aerLingus.add(planeStore);

        aerLingus.printPlane();
    }

}

import java.util.TreeMap;


public class PlaneStore 
{
    private String airlineName;
    private TreeMap<String,Flight> planeMap;


    public PlaneStore(String airlineName) 
    {
        this.airlineName = "";
        planeMap = new TreeMap<String,Flight>();
    }


    public String getAirlineName() {
        return airlineName;
    }


    public TreeMap<String, Flight> getFlightList() {
        return planeMap;
    }
    public void addFlight(String airline,Flight flight)
    {
        planeMap.put(airline, flight);
    }

    // ---------------------------------------------------------------------------------------
    // Name: Print.
    // ---------------------------------------------------------------------------------------
    public void print()
    {
        System.out.println("\n********Student's in the Company.********");
        for (Flight flight : planeMap.values()) {
            // System.out.println(employee); to print the toString of Employee
            // class
            // or:
            System.out.println("Airline:\t" + flight.getAirline());
            System.out.println("Flight Number:\t" + flight.getFlightNumber());
            System.out.println("Fuel Remaining:\t" + flight.getFuelRemaining());
        }

    }


}
public class Flight 
{
    private String airline;
    private String flightNumber;
    private double fuelRemaining;
    private double overdue;
    private int passengerNumber;
    private AIRPLANETYPE planeType;

    public enum AIRPLANETYPE
    {
        AIRBUS("1"), CORPORATE("2"), PRIVATE("3");

        private String planeName;

        private AIRPLANETYPE(String planeName)
        {
            this.planeName = planeName;
        }
    }


    public Flight(String airline, String flightNumber, double fuelRemaining,
            double overdue, int passengerNumber, AIRPLANETYPE planeType) 
    {
        super();
        this.airline = airline;
        this.flightNumber = flightNumber;
        this.fuelRemaining = fuelRemaining;
        this.overdue = overdue;
        this.passengerNumber = passengerNumber;
        this.planeType = planeType;
    }

    public String getAirline() {
        return airline;
    }

    public void setAirline(String airline) {
        this.airline = airline;
    }

    public String getFlightNumber() {
        return flightNumber;
    }

    public void setFlightNumber(String flightNumber) {
        this.flightNumber = flightNumber;
    }

    public double getFuelRemaining() {
        return fuelRemaining;
    }

    public void setFuelRemaining(double fuelRemaining) {
        this.fuelRemaining = fuelRemaining;
    }

    public double getOverdue() {
        return overdue;
    }

    public void setOverdue(double overdue) {
        this.overdue = overdue;
    }

    public int getPassengerNumber() {
        return passengerNumber;
    }

    public void setPassengerNumber(int passengerNumber) {
        this.passengerNumber = passengerNumber;
    }

    public AIRPLANETYPE getPlaneType() {
        return planeType;
    }

    public void setPlaneType(AIRPLANETYPE planeType) {
        this.planeType = planeType;
    }


    public String toString() 
    {
        return "Flight [airline=" + airline + ", flightNumber=" + flightNumber
                + ", fuelRemaining=" + fuelRemaining + ", overdue=" + overdue
                + ", passengerNumber=" + passengerNumber + ", planeType="
                + planeType + "]";
    }




}
  • 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-15T17:29:35+00:00Added an answer on June 15, 2026 at 5:29 pm

    HashMap is a data structure in which you are able to store key-value pairs. It essential that the key is unique. Otherwise you overwrite the value that has the same key.

    With this data structure you are able to add and find values very quickly because the complexity of adding and finding values is constant. But the disadvantage is that you can only add a key one time.

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

Sidebar

Related Questions

Hey guys I'm trying to make a basic calculator (polish style) but can't figure
Hey guys I'm trying to make a GUI which can navigate through JTextAreas when
Hey im trying to add countdown timers to an arraylist but it is crashing.
Hey there, i am trying to make a little app that will serve multiple
Hey guys, I'm trying to make a puzzle bubble clone but I'm stumped on
Hey I am very new to python but I am trying to make a
Hey, I'm trying to make a little feature where I can click on an
hey guys was hoping you could help me out. I am trying to make
Hey I am trying to make a dungeon crawler and I am stuck on
Hey all I'm trying to make a 3d game in with 2d sprite characters.

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.