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

  • Home
  • SEARCH
  • 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 7500869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:20:20+00:00 2026-05-29T20:20:20+00:00

I’m kind of stumped here. I’m relatively new to Java/Programming in general. I want

  • 0

I’m kind of stumped here.

I’m relatively new to Java/Programming in general. I want to make a program that “books seats” in a 4×4 grid. This multidimensional array will be of the type boolean so that if the seat is not taken, it returns false, but if it is taken it will return true. I want to be able to specify different seats, so like the first two rows will be a different section than the last two rows. Right now I have a method but it just books the entire first two rows as soon as I call that method (as it should, logically speaking). But I want to only be able to book one seat at a time, so that it will end that for loop as soon as one seat is booked. If I select that I want to book another seat, it will move to the next available seat in those rows or columns.

Here is the code so far:

import javax.swing.JOptionPane;

public class Seats{
int maxRows = 4;
int maxCols = 4;
boolean seating[][] = new boolean[maxRows][maxCols];

String bookSeat = null;

public static void main(String []args){
    Seats seats = new Seats();
    seats.start();

}

public void start(){
    bookSeat = JOptionPane.showInputDialog(null, "Book a seat? (y/n)");
    if(bookSeat.equals("y")){
        bookSeat();
    }else{
        JOptionPane.showMessageDialog(null, "Okay.");       
    }
    displaySeats(seating);
}

private boolean bookSeat(){
    boolean isBooked = false;
    for(int row = 0; row <2; row++){
        for(int col = 0;col<maxCols;col++){
            if (seating[row][col] == false){
                seating[row][col] = true;
                isBooked = true;
            }
        }
    }
    return isBooked;

}

private void displaySeats(boolean[][] anArray){

    String seatTaken;
    int r=0;
    int c=0;
    for(int display=0; display<1; display++){
        for(r=0;r<anArray.length;r++){
            for(c=0;c<anArray.length;c++){
                if (seating[r][c]==false){
                    seatTaken = "O";
                }
                else{
                    seatTaken = "X";
                }
            System.out.print("\t[" + seatTaken + "] \t");

            }
            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-05-29T20:20:21+00:00Added an answer on May 29, 2026 at 8:20 pm
    private boolean bookSeat(){
        boolean isBooked = false;
        for(int row = 0; row <2; row++){
            for(int col = 0;col<maxCols;col++){
                if (seating[row][col] == false){
                    seating[row][col] = true;
                    return true;
                }
            }
        }
        return false;
    }
    

    I think what you’re looking to do is return once you find an open seat and book it — as shown in the method above. This way the loops won’t continue once you book a seat.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.