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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:50:31+00:00 2026-06-01T02:50:31+00:00

Ok, so I’m trying to finish our simple project for Data Strcutures but there

  • 0

Ok, so I’m trying to finish our simple project for Data Strcutures but there is always some error that just keep showing up on my program. I have fixed some of them but there is this one that makes me want to give up. Maybe you guys could help me find the solution?

Here is my code (class LogInSystem):

    // NMQ

    import java.util.ArrayList;
    import java.util.Scanner;
    import java.util.Vector;

public class LogInSystem {
    private static final int MAX_SEATS = 10;

    Vector<String> username = new Vector<String>();
    ArrayList<String> password = new ArrayList<String>();

    int p;
    String Username, Password, rUsername, rPassword;

    private Scanner input = new Scanner(System.in);


    public LogInSystem() {
        loginScreen();
    }
    private void loginScreen() {
        boolean done = false;

        do {
            printMainMenu();
            int choice = getMainMenuChoice();

            switch (choice) {
            case 1: // Log In
                logIn();
                break;

            case 2: // To Register
                register();
                break;

            case 3: // Exit
                done = true;
                break;
            }

        } while (!done);
    }

    //Registration

    private void register() {
        System.out.println("Input a Username");
        Username = input.next();
        System.out.println("Input a Password");
        Password = input.next();
        System.out.println("... Registered!");

    }

    //Log In

    private void logIn() {
        p = 0;
        System.out.println("Input a Username");
        rUsername = input.next();
        System.out.println("Input a Password");
        rPassword = input.next();

        // If the log in is successful it will got to the next menu

        if(rUsername.equals(Username)&& rPassword.equals(Password))
        {
            System.out.println("... Logging In");
            boolean done = false;

            String[] seats = new String[MAX_SEATS]; // the item list
            initializeItems(seats);
         // Printing of 2nd menu
            do {
                printMainMenu2();
                int choice = getMainMenuChoice2(); // choice off of the main menu

                switch (choice) {
                case 1: // Adding Seat
                    addSeat(seats);
                    break;
                case 2: // Viewing Seat List
                    viewSeatList(seats);
                    break;
                case 3: // Exit
                    done = true;
                    break;
                }

            } while (!done);
        }

        else
            System.out.println("Invalid log in, please try again.");

    }
    private int getMainMenuChoice() {
        int choice; // choice entered
        boolean valid = false; // is choice valid?

        do {
            System.out.print(">>>>> ");
            choice = cineplexError.readInt();

            if (1 <= choice && choice <= 4) {
                valid = true;
            } else {
                System.out.println("Invalid choice.");
            }
        } while (!valid);

        return choice;
    }
    private void printMainMenu() {
        System.out.println("\nMain Menu\n");
        System.out.println("Press 1 to Log In");
        System.out.println("Press 2 to Register");
        System.out.println("Press 3 to Exit");
        System.out.println();
    }
    public static void main(String[] args) {
        new LogInSystem();
    }

    int getMainMenuChoice2() {
        int choice; // choice entered
        boolean valid = false; // is choice valid?

        do {
            System.out.print(">>>>> ");
            choice = cineplexError.readInt();

            if (1 <= choice && choice <= 4) {
                valid = true;
            } else {
                System.out.println("Invalid choice.");
            }
        } while (!valid);

        return choice;
    }
    void printMainMenu2() {
        System.out.println("\nMain Menu\n");
        System.out.println("Press 1 to Reserve a Seat");
        System.out.println("Press 2 to View the Seat List");
        System.out.println("Press 3 to Exit Buying");
        System.out.println();
    }
    void initializeItems(String[] seats) {
        for (int i = 0; i < seats.length; i++) {
            seats[i] = "";
        }
    }
    void addSeat(String[] seats) {
           int seatIndex = findEmptySeatList(seats); // index of first empty item list
            if (seatIndex == seats.length) {
                System.out.println("Seat is already occupied. Sorry.");
            } 

            else {
                String seat = getSeatName(); // seat's name
                seats[seatIndex] = seat;
                System.out.println(seat + " is on seat list #"
                        + (seatIndex + 1));
            }
        }
    int findEmptySeatList(String[] seat) {
        for (int i = 0; i < seat.length; i++) {
            if (isEmpty(seat, i)) {
                return i;
            }
        }

        return seat.length;
    }
    boolean isEmpty(String[] seats, int seatIndex) {
        return seats[seatIndex].equals("");
    }
    String getSeatName() {
        System.out.print("Enter the name of reservator: ");
        return cineplexError.readString();
    }
    void viewSeatList(String[] seats) {
        System.out.println("\nSeat List\n");
        for (int i = 0; i < seats.length; i++) {
            System.out.println((i + 1) + ". " + seats[i]);
        }
    }
}

Here is the other class (cineplexError):

// NMQ

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class cineplexError {
    private  static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private  static String integerReprompt = "Invalid integer. Try again: ";
    private  static String doubleReprompt = "Invalid double. Try again: ";
    private  static String charReprompt = "Invalid character. Try again: ";

    public static String readString() {
        String s = null;
        try {
            s = in.readLine();
        } catch (IOException ex) {}
        return s;
    }

    public static char readChar() {
        char c = 0;
        String s = null;
        try {
            s = in.readLine();
        } catch (IOException ex) {}
                if (s.length() == 1) {
                    c = s.charAt(0);
//                  valid = true;
                } else {
                    System.out.print(charReprompt);
                }
        return c;
    }

    public static int readInt() {
        int i = 0;

            boolean valid = false;

            try {
                    i = Integer.parseInt(in.readLine());
            } catch (IOException ex) {
                System.out.print(integerReprompt);
                }
                    valid = true;



        return i;
    }

    public static double readDouble() {
        double d = 0.0;

        boolean valid = true;

        try {
                    d = Double.parseDouble(in.readLine());
        } catch (IOException ex) {}
                    valid = true;
                    valid = false;
                    System.out.print(doubleReprompt);


        return d;
    }

    public void pause() {
            System.out.print("Press enter to continue...");
            try {
            in.readLine();
            } catch (IOException ex) {}
        }

    public static void setIntegerReprompt(String prompt) {
        integerReprompt = prompt;
    }

    public void setDoubleReprompt(String prompt) {
        doubleReprompt = prompt;
    }

    public void setCharReprompt(String prompt) {
        charReprompt = prompt;
    }

 }

The bug in the program is that whenever I reserve a seat and log out and log in again the name of the reservator or the name of the one that reserves a seat is being erased when I view the seat list. Should I put a control statement that makes the value stored permanently? Can you help me out?
Thanks.

  • 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-01T02:50:33+00:00Added an answer on June 1, 2026 at 2:50 am
    Line 73:   String[] seats = new String[MAX_SEATS]; // the item list
    Line 74:   initializeItems(seats);
    

    Every time you call logIn you are re-initializing the list of seats to all empty strings. That initialization should be done in the constructor. So move Line 73 (declaration of String[] seats) to be an instance variable of the class, and move Line 74 to be in the constructor.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.