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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:46:57+00:00 2026-06-07T11:46:57+00:00

for my project, i have an arraylist for the user to input whatever names

  • 0

for my project, i have an arraylist for the user to input whatever names they want in one method as long as it isn’t stop. then in a separate method, the values i just inputted have to be called out again, so i can input more information for each name.

example:

  1. enter names:
  2. name: bob
  3. name: joe
  4. name: Stop
    this triggers another method to prompt more info:

  5. bob:
    enter age:
    enter address:

  6. joe:
    enter age:
    enter address:

    However, right now, the arraylist isn’t printing out correctly, and i’m getting repeats of certain names, while other names don’t show up in the second method. Also, the loop in the second method doesn’t end. i enter in info for the names i entered, but i keep getting prompted with “name:” and no actual arraylist value. I suspect something is wrong with my loops, but i don’t quite know how to fix it? I also thought that maybe the problem has something to do with how i’m using a wrapper to put in values into the arraylist, but i don’tknow how to fix that.

in the second method, I’ve tried swapping the countervariable to keep track of the order in the Array List with a separate counter in the second method, but it doesn’t seem to make a difference. In the first method, i’ve tried swapping the loop with different a boolean while loop, with a straight up while (!input.equals(“Stop”)), a for loop counter inside of the previous two options, if loops, and some combination of the above.

here is my code

Scanner console = new Scanner(System.in);
private ArrayList<Directory> nameList; //i have to use object oriented programming to store values in the Directory Class
public int i;

first method:

private void addName() 
{
    Scanner LocalInput = new Scanner(System.in);
    Directory buffer = null;
    String ID = null;

    System.out.println("Enter Station Designations Below, Enter Stop to quit");
    boolean breaker = false;
    while(breaker ==false)
    {
        System.out.print("Name:  ");
        ID = (LocalInput.nextLine());
        if(ID.equals("Stop"))
            breaker = true;
        else
            buffer = new Directory(ID); 
            nameList.add(buffer); 
    }
}

second method:

private void getInfo()
{
    Scanner LocalInput = new Scanner(System.in);

    Directory buffer;
    buffer = nameList.get(i); 
    double age; String address;


    System.out.println("Enter Temperatures below...");
    System.out.println("" + nameList.get(i));

    for (i = 0; i < nameList.size(); i++) 
    {

        System.out.println("Name: " + buffer.GetID()); //there's a getter and setter in the Directory class
        System.out.println( "Age:\t");
        age = LocalInput.nextDouble();
        System.out.print( "Address:\t");   
        address = LocalInput.nextLine();
        buffer= new Directory(age, address);
        nameList.add(buffer);
    }
}
  • 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-07T11:46:59+00:00Added an answer on June 7, 2026 at 11:46 am

    Critique of first method

    I haven’t looked closely yet, but I strongly suspect this is the problem:

    if(ID.equals("Stop"))
        breaker = true;
    else
        buffer = new Directory(ID); 
        nameList.add(buffer); 
    

    You appear to be expecting the last statement only to be executing when ID is not equal to “Stop”, but actually it’s always going to execute. Unlike (say) Python, whitespace is irrelevant in Java. If you statements to be considered as a block, you need braces:

    if(ID.equals("Stop"))
        breaker = true;
    else {
        buffer = new Directory(ID); 
        nameList.add(buffer); 
    }
    

    Personally I would put braces around both parts:

    if (ID.equals("Stop")) {
        breaker = true;
    } else {
        buffer = new Directory(ID); 
        nameList.add(buffer); 
    }
    

    … and quite possibly get rid of the somewhat-irrelevant buffer variable:

    if (ID.equals("Stop")) {
        breaker = true;
    } else {
        nameList.add(new Directory(ID));
    }
    

    I’d also get rid of the breaker variable, and limit the scope of ID (changing its name, too, to comply with normal conventions) with a result of:

    while (true) {
        System.out.print("Name:  ");
        string id = LocalInput.nextLine();
        if (id.equals("Stop")) {
            break;
        }
        nameList.add(new Directory(ID));
    }
    

    Critique of second method

    This is really odd at the moment. It’s not at all clear where the i variable is declared, or why you only fetch buffer once, or why you’re just adding to the existing list rather than mutating the existing object. I suspect you really want:

    for (Directory entry : nameList) {
        System.out.println("Name: " + entry.GetID());
        System.out.println( "Age:\t");
        double age = LocalInput.nextDouble();
        entry.setAge(age);
        System.out.print( "Address:\t");   
        String address = LocalInput.nextLine();
        entry.setAddress(address);
    }
    

    Note that your current loop will always continue until i equals nameList.size() – but you’re always increasing the size in the loop, so you’ll never terminate.

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

Sidebar

Related Questions

I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
I want to apply NTFS-Search to our project. Our project have to find the
I have project I want to upgrade to .Net4 and it use BackgroundCopyManager.dll. Anyone
I have project in Dropbox and two running laptops: one with Ubuntu and one
hi i have more than 10 arraylist in my project, i need to compare
I have a simple test project in Spring 3, basically a method within the
In my current project I have an ArrayList of PVectors that store xyz coordinates
hello friends in my project i have an arraylist showing results in a jsp
I am using the wicket 1.3 CheckBoxMultipleChoice() method to have the user select relevant
I have a arraylist in my web application project in asp.net/C#/VS2008 and I'm using

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.