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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:26:07+00:00 2026-06-15T13:26:07+00:00

The code I have produced is meant to provide functionality of reading a text

  • 0

The code I have produced is meant to provide functionality of reading a text file line by line, saving each line into an array. It seems to read in each line correctly but when I use the printProps() method it only displays one…

Code is only saving one line of a text file to the array, what’s wrong with my code?

/*reading in each line of text from text file and passing it to the processProperty() method.*/
Public void readProperties(String filename) {
    try {
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        int i = 0;
        String line;
        line = reader.readLine();
        while (line != null && !line.equals("")) {
            i++;
            processProperty(line);
            line = reader.readLine();
        }
        System.out.println("" + i + " properties read");
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();

    }
}

/*Breaks up the line of text in order to save the value to an array (at this point it only saves one line to the array). org.newProp(newProp) passes the new property to the Organize class where it saves it to an array.

public void processProperty(String line) {
         org = new Organize();
        int id = nextPropertyID;
        nextPropertyID++;

        String[] parts = line.split(":");
        int propNo = Integer.parseInt(parts[0]);            
        String postcode = parts[1];
        String type = parts[2];
        int bedrooms = Integer.parseInt(parts[3]);
        int year = Integer.parseInt(parts[4]);
        int rental = Integer.parseInt(parts[5]);
        Landlord landlord = theLandlord;
        Tenant tenant = null;
        org.propUniqueCheck(id);
        propNoCheck(propNo, postcode);
        postcodeCheck(postcode,propNo);
        typeCheck(postcode, propNo, type);
        bedroomsCheck(bedrooms, postcode, propNo);
        yearCheck(propNo, postcode, year);
        System.out.println("Creating property " + id);

        Property newProp = new Property(id, propNo, postcode, type, bedrooms, year,
                rental, landlord, tenant);
        org.newProp(newProp);
        org.printProps();
    }

/*From here down it is the code to save the value to the array*/

public Organize() {
        props = new ArrayList<Property>();
        PTs = new ArrayList<PotentialTenant>(); 
        waitingList = new LinkedList<String>();
        //myList.add(new prop(Property.toString()));

    }
    public void newProp(Property p)
    {
        props.add(p);
    }

I have actively been seeking help in my seminar with this problem and I can’t seem to find a solution, any advice would be very much appreciated!

  • 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-15T13:26:08+00:00Added an answer on June 15, 2026 at 1:26 pm

    In processProperty you are instantiating a new Organize object. Therefore, each Property (which you create for each row) is ending up in a different ArrayList (as the first element).

    One solution would be to instantiate one Organize object before you start your loop and then pass this into your processProperty method as a parameter.

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

Sidebar

Related Questions

I have some code that produces undefined values in an array making no sense.
I have the following code that produces a background image in a table cell.
I have an application which uses code that produces various types of objects and
I just have a system crash and reinstall Ubuntu 11.10, and my code produces
this is function.php of a wordpress theme that NOD32 says this code have a
Code I have written involves getting the time waiting for 10 minutes and then
I have code that generates a List<string[]> variable but can't quite figure out how
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have code which has a drop down list. And when a certain option
I have code that looks more or less like the code below but it

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.