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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:11:31+00:00 2026-05-26T23:11:31+00:00

I have two arrays the store the values of two lines that are read

  • 0

I have two arrays the store the values of two lines that are read in from a file. After some processing in my GUI class it should show to rectangles side by side in the middle of the frame. However only one ever shows up. I have tried every way I know how to get the other one to show up but no dice. Here is my code:

public class PortraitFileReader 

    public static ArrayList<Drawable> readFile(File a) {
    File myFile;
    ArrayList<Integer> values = new ArrayList<Integer>();
    ArrayList<Drawable> couple = new ArrayList<Drawable>();
    Man aMan;
    Woman aWoman;
    Point aPoint;
    String input;
    String [] array = null;
    String [] array2 = null;
    try {
        myFile = a;
        Scanner inFile = new Scanner(myFile);
        input = inFile.nextLine();
        array = input.split(", ");

        while(inFile.hasNext()) {
            input = inFile.nextLine();
            array2 = input.split(", ");
            System.out.println(Arrays.toString(array2));        
        }

        if(array[0].equals("man")) {
            for(int i=1; i<array.length-1; i++) {
                    int current = Integer.parseInt(array[i]);
                    values.add(current);
                    System.out.println(values);
                }
                aPoint = new Point(values.get(0), values.get(1));
                aMan = new Man(aPoint, values.get(2), values.get(3), array[5]);
                couple.add(aMan);
                values.clear();


        }

        if(array[0].equals("woman")) {
            for(int i=1; i<array.length-1; i++) {
                int current = Integer.parseInt(array[i]);
                values.add(current);
                System.out.println(values);
            }
            aPoint = new Point(values.get(0), values.get(1));
            aWoman = new Woman(aPoint, values.get(2), values.get(3), array[5]);
            couple.add(aWoman);
            values.clear();
        }

        if(array2[0].equals("man")) {
            for(int i=1; i<array2.length-1; i++) {
                int current = Integer.parseInt(array[i]);
                values.add(current);
                System.out.println(values);
            }
            aPoint = new Point(values.get(0), values.get(1));
            aMan = new Man(aPoint, values.get(2), values.get(3), array2[5]);
            couple.add(aMan);
            values.clear();
        }

        if(array2[0].equals("woman")) {
            for(int i=1; i<array2.length-1; i++) {
                    int current = Integer.parseInt(array[i]);
                    values.add(current);
                    System.out.println(values);
                }
            aPoint = new Point(values.get(0), values.get(1));
            aWoman = new Woman(aPoint, values.get(2), values.get(3), array2[5]);
            couple.add(aWoman);
            values.clear();
        }
    }

    catch (FileNotFoundException e) {
        System.out.println("The file was not found.");
    }
    return couple;
}
}

This is the data that I’m reading in from the file:

man, 260, 100, 40, 80, Tom  
woman, 300, 100, 40, 80, Sally  

Any help would be greatly appreciated.

NOTE: the system.out.println’s are just there to test if each array had the right values in it.

  • 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-26T23:11:31+00:00Added an answer on May 26, 2026 at 11:11 pm

    When you are going through array2 checking if it is a woman, you are actually going through the variable array.

     for(int i=1; i<***array2***.length-1; i++) {
    int current = Integer.parseInt(****array***[i]);
    

    The same goes for when you are checking if array2 is a man

    The effect of this is that you are processing the contents of the first line twice.

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

Sidebar

Related Questions

I have two arrays, @names and @employees , that are filled with strings that
I have two arrays. I'd like to copy ranges of data from one of
I have two arrays with time values in them in this format. 00:00:00 which
I have a file which contains two JSON arrays; one is holding the column
I have two multidimensional arrays which store x and y coordinates I am trying
I have two NSMutableArrays(arrayContainsGoodClicks and arrayContainsBadClicks). I am initializing these Arrays with some NSTimeInterval
I have two arrays built from an XML response to an api. One array
I have two arrays and I post the arrays in one input; <input name='sistem[]'
I have two arrays in JavaScript: var xcoord = []; and var ycoord =
I have two arrays in JSON something like: proj1 proj1 taska taska charge1 charge1

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.