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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:16:54+00:00 2026-06-13T21:16:54+00:00

So basically I want to fill an array with objects and then display it.

  • 0

So basically I want to fill an array with objects and then display it. (Later these objects will be able to be Seat as ‘Booked’ which will make them be displayed as an X in the array.)

However I keep getting an error whenever I go to execute the methods that would make and display the array.

Here is my code:

Main:

public static void main(String[] args) {


        Seat cinemaactual = new Seat("Cinema");
        Seat[][] cinema = new Seat[10][22];

        Ticket ticket = new Ticket();
        Scanner scan = new Scanner(System.in);
        String answer, contiune;



        int number, check = 0, category, id;




        do {



            System.out.print("Welcome to the Theatre Booking System. (QUIT to exit)"
                    + "\nWould you like to purchase tickets or list available seats?"
                    + "(/Purchase/List/Help)");
            answer = scan.nextLine();

            if (answer.equalsIgnoreCase("purchase")) {
                do {

                    System.out.println("Please choose the cateogry of ticket "
                            + "you would like, followed by who the ticket is for"
                            + "and the amount required. (separated by a space)\n"
                            + "1. Gold\n2. Silver\n3. Bronze\n\n1. Adult\n2."
                            + " Child\n3. Concession");
                    category = scan.nextInt();
                    number = scan.nextInt();
                    id = scan.nextInt();
                    if (category == 1 || category == 2 || category == 3 && id == 1 || id == 2 || id == 3) {

                        ticket.SetType(category);
                        if (category == 1) {
                            ticket.SetName("Gold");
                        } else if (category == 2) {
                            ticket.SetName("Siler");
                        } else {
                            ticket.SetName("Bronze");
                        }
                        ticket.SetNumber(number);
                        ticket.SetID(id);
                        if (id == 1) {
                            ticket.SetCategory("Adult");
                        } else if (id == 2) {
                            ticket.SetCategory("Child");
                        } else {
                            ticket.SetCategory("Bronze");
                        }
                        System.out.print("You have selected"
                                + ticket.GetNumber() + " " + ticket.GetName()
                                + " ticket(s) at the" + ticket.GetCategory() + " price .");

                        ticket.BuyTicket(category, id, number);


                    } else {

                        System.out.print("Sorry, incorrect input, please enter an apropriate value.");
                        check = scan.nextInt();
                    }
                } while (check == 0 || check > 3);

                do {
                    System.out.print("Would you like to perchase more tickets? (Yes/No)");
                    contiune = scan.nextLine();




                } while (contiune.equalsIgnoreCase("Yes"));



            } else if (answer.equalsIgnoreCase("list")) {
                cinemaactual.CreateTheatre(cinema);
                cinemaactual.DisplayTheatre(cinema);

            } else if (answer.equalsIgnoreCase("help")) {
                // Code for help
            } else if (answer.equalsIgnoreCase("quit")) {
                System.exit(-1);
            }

            System.out.print("Sorry, incorrect input please enter"
                    + " a valid input (Purchase/List/Help or QUIT to exit");
            answer = scan.nextLine();

        } while (!answer.equalsIgnoreCase("purchase")
                || !answer.equalsIgnoreCase("List")
                || !answer.equalsIgnoreCase("help")
                || !answer.equalsIgnoreCase("quit"));


    }

Seat Class Methods that would create/Fill Array:

    public void SetType(String x) {

        type = x;
    }

    public boolean SetStatus() {
        return status;
    }

    public void GetStatus(boolean x) {
        status = x;
    }

    public String toString() {
        String Seat = type;

        return type;
    }

    public String BookSeat() {
        type = "x";
        return type;
    }

    public Seat[][] CreateTheatre(Seat[][] x) {


        for (int row = 0; row < 4; row++) {
            for (int col = 0; col < 8; col++) {
                x[row][col] = new Seat("B");
            }
            for (int col = 8; col < 12; col++) {
                x[row][col] = new Seat("S");
            }
        }
        for (int row = 19; row < 23; row++) {
            for (int col = 0; col < 8; col++) {
                x[row][col] = new Seat("B");
            }
            for (int col = 8; col < 12; col++) {
                x[row][col] = new Seat("S");
            }
        }
        for (int row = 4; row < 9; row++) {
            for (int col = 3; col < 5; col++) {
                x[row][col] = new Seat("B");
            }
            for (int col = 5; col < 9; col++) {
                x[row][col] = new Seat("S");
            }
        }
        for (int row = 4; row < 7; row++) {
            for (int col = 9; col < 12; col++) {
                x[row][col] = new Seat("S");
            }
        }
        for (int row = 14; row < 20; row++) {
            for (int col = 3; col < 5; col++) {
                x[row][col] = new Seat("B");
            }
            for (int col = 5; col < 9; col++) {
                x[row][col] = new Seat("S");
            }
        }
        for (int row = 16; row < 20; row++) {
            for (int col = 9; col < 12; col++) {
                x[row][col] = new Seat("S");
            }
        }
        for (int row = 9; row < 14; row++) {
            for (int col = 6; col < 9; col++) {
                x[row][col] = new Seat("G");
            }
        }
        for (int row = 7; row < 16; row++) {
            for (int col = 9; col < 12; col++) {
                x[row][col] = new Seat("G");
            }
        }
        return x;
    }

    public void DisplayTheatre(Seat[][] x) {
        for (int row = 0; row < x.length; row++) {
            for (int col = 0; col < x[row].length; col++) {
                System.out.print(x[row][col]);
            }
            System.out.println();
        }
    }
}
  • 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-13T21:16:56+00:00Added an answer on June 13, 2026 at 9:16 pm

    In CreateTheatre(...) you first have to make sure, that the arrays are actually as large, as you process in the for loops, if they are smaller, trying to access them throws an ArrayIndexOutOfBoundsException.

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

Sidebar

Related Questions

I have a 2-dimensional array of objects and I basically want to databind each
I basically want to do: git checkout branchA git checkout -b branchB <commit_id> which
I basically want to be able to deploy multiple versions of the same EAR
I basically want to make things easier by just looping LinkButtons instead of making
I basically want to make this in my application, so our technicians have an
I basically want to display a rectangle on a dialog window widget. Using another
I'm trying to build a hash from an array. Basically I want to take
How do you fill a NSMutableArray with a set capacity for later use? Basically
Basically I am working on a review form in which users fill out items
I basically want something like: TextView Button Button . . . TextView TextView SeekBar

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.