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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:17:30+00:00 2026-06-16T00:17:30+00:00

I am supposed to write a program that could accept user input of aircraft

  • 0

I am supposed to write a program that could accept user input of aircraft name, destination, number of passengers and flight time. The user is asked if how many aircrafts he/she would like to process. I know that I should make use of arrays. Here’s my current codes but it stops after the input of the first aircraft name.

here’s what’s happening:

Enter airline company: French Air
Enter number of aircrafts to process: 3
Enter aircraft name: ABC
Enter destination: Tokyo
Enter number of passengers: 156
Enter flight time: 10:15
Enter aircraft name: DEF
Enter destination: Chile
Enter number of passengers: 88
Enter flight time: 11:00
Enter aircraft name: FGH
Enter destination: Miami
Enter number of passengers: 157
Enter flight time: 12:00

Today’s report of international fligts forFrenchAir

AIRCRAFTS DESTINATION NUMBER OF PASSENGERS FLIGHT TIME
ABC Tokyo 156 10:15
DEF Chile 88 11:00
FGH Miami 157 12:00

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4
at AircraftsReport.main(AircraftsReport.java:54)

Here my current codes:

import java.util.*;

public class AircraftsReport 
{
    public static void main(String[] args)
    {
            Scanner input = new Scanner(System.in);

        String airline = "";
        String strAircraft = "", strDestination = "", strFlightTime = "";
        int passengersCount = 0, num2process = 0, ctr = 0, ctr2 = 0;

            System.out.print("Enter airline company: ");
        airline = input.nextLine();

        System.out.print("Enter number of aircrafts to process: ");
        num2process = input.nextInt();

        String[] AIRCRAFTS = new String[num2process];
        String[] DESTINATIONS = new String[num2process];
        String[] FLIGHT_TIME = new String[num2process];
            int[] PASSENGERS_COUNT = new int[num2process];

        while(ctr < num2process)
        {
            System.out.print("Enter aircraft name: ");
            strAircraft = input.next();
            AIRCRAFTS[ctr] = strAircraft;

            System.out.print("Enter destination: ");
            strDestination = input.next();
            DESTINATIONS[ctr] = strDestination;

            System.out.print("Enter number of passengers: ");
            passengersCount = input.nextInt();
            PASSENGERS_COUNT[ctr] = passengersCount;

            System.out.print("Enter flight time: ");
            strFlightTime = input.next();
            FLIGHT_TIME[ctr] = strFlightTime;

            ctr++;

        }


        System.out.println("Today's report of international fligts for" +
                        airline);

        System.out.println("\nAIRCRAFTS\tDESTINATION\tNUMBER OF PASSENGERS" +
                "\tFLIGHT TIME");

        for(ctr2 = 0; ctr2 <= AIRCRAFTS.length; ctr2++)
        {
            System.out.print(AIRCRAFTS[ctr2] + "\t" + DESTINATIONS[ctr2] + 
                    "\t" + PASSENGERS_COUNT[ctr2] + "\t" + FLIGHT_TIME[ctr2]);
            System.out.println();

        }

    }

}

Please help with figuring out what’s wrong

It produces the output together with the Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4
at AircraftsReport.main(AircraftsReport.java:54)

  • 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-16T00:17:31+00:00Added an answer on June 16, 2026 at 12:17 am

    In this line

    int passengersCount = 0, num2process = 0, ctr = 0, ctr2 = 0;
    

    you declare num2process as 0.

    So the next line

    String[] AIRCRAFTS = new String[num2process];
    

    creates an array of 0 length.

    A few lines after that you reassign num2process:

    num2process = input.nextInt();
    

    but this won’t change the size of the previously created array.

    You enter the do while loop once (because they always get executed at least once), and the condition check subsequently fails

    } while(ctr < AIRCRAFTS.length);
    

    because ctr is 1 at this point (after executing ctr++;) and AIRCRAFTS.length is still 0.

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

Sidebar

Related Questions

I am supposed to write a program that gets some PNG images from the
I'm supposed to write a wrapper function to MD5 hashing that restricts the input
I am learning Java. I am supposed to write a program that converts all
I am supposed to write a program in JavaScript to find all the anagrams
I have simple serial port program that is supposed to read the serial port
Part of my program is to calculate sqrt of float number. When I write
Background: my assignment was to write a program that uses linked list to keep
for an assignment in my Java class I'm supposed to write a program for
I'm trying to write a program that is just a little beyond my abilities.The
My program is supposed to be installed to a path that recorded in registry.

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.