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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:53:11+00:00 2026-06-14T06:53:11+00:00

I am developing in NetBeans and want to know why does this code run

  • 0

I am developing in NetBeans and want to know why does this code run when I press F6? I have no main method. When I press F6, the code runs the method LoadListings and loads the arraylist from “houses.txt” located on my hard drive. It does not run the LoadArray method just before, so only the text file data is printed at the end.

package housetracker;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;


public class HouseList {

List<House> houseList;
private String defaultFileName = "houses.txt";
private String fileSeparator = System.getProperty("file.separator");
private String workingDirectory = (System.getProperty("user.dir") + this.fileSeparator);
private String listingsFile = workingDirectory + "txt_files" + this.fileSeparator +  defaultFileName;
private BufferedReader br;
private FileReader fr;
private String line;
private Integer address;
private String street;
private double price;
private int rooms;
DecimalFormat moneyFormat = new DecimalFormat("0.00");

public HouseList() {
    houseList = new ArrayList();

}

public void FillArray() {
    fillArray();
}

private void fillArray() {
    houseList.add(new House(123, "Main", 75000.00, 2));
    houseList.add(new House(621, "Mystreet", 175000.00, 5));
    houseList.add(new House(4568, "1st", 725000.00, 8));
    houseList.add(new House(5546, "Broadway", 85600.00, 3));
    houseList.add(new House(8744, "Texas", 195610.00, 6));
    houseList.add(new House(45454, "Maine", 125000.00, 4));
    houseList.add(new House(4465, "Main", 375000.00, 2));
}

public void LoadListings(String fileName) {
    loadListings("C:\\\\temp\\houses.txt");
}
//Load the listings file into the array.

private void loadListings(String fileName) {
    // Clear variables
    this.br = null;
    this.fr = null;
    this.line = null;

    try {
        // Set FileReader to access the user specified file name.
        this.fr = new FileReader(fileName);
        System.out.println(fr);
        // Use a BufferedReader to load file into memory.
        this.br = new BufferedReader(this.fr);
        System.out.println(br);
        System.out.println("*****************************************************\n");

        // Read file contents a line at a time until file returns null.
        while ((line = this.br.readLine()) != null) {
            System.out.println(line);

            // Let StringTokenizer parse each line and split data into elements 
            // using an empty space as the separator.  
            StringTokenizer stringTokenizer = new StringTokenizer(line, " ");

            // Loop through each each element of the line 
            while (stringTokenizer.hasMoreElements()) {
                this.address = Integer.parseInt(stringTokenizer.nextElement().toString());
                this.street = stringTokenizer.nextElement().toString();
                this.price = Double.parseDouble(stringTokenizer.nextElement().toString());
                this.rooms = Integer.parseInt(stringTokenizer.nextElement().toString());
                // Format price to look like money.
                moneyFormat.format(this.price);

                // Build a string just because I can
                StringBuilder sb = new StringBuilder();
                sb.append("*******************");
                sb.append("\nAddress    : ").append(this.address);
                sb.append("\nStreet  : ").append(this.street.toUpperCase());
                sb.append("\nPrice : ").append(this.price);
                sb.append("\nRooms       : ").append(this.rooms);
                sb.append("\n*******************");
                System.out.println(sb.toString());

                // Add data to array
                houseList.add(new House(this.address, this.street, this.price, this.rooms));
            }
        }

        System.out.println("*****************************************************");
        System.out.println("Array is loaded");
        // Set a variable indicating array is loaded and ready for transactions.
        //this.isArrayLoaded = true;

    } catch (IOException e) {
        // Catch any IO errors while accessing the file and alert the user.
        System.out.println("An IO error occured while accessing " + fileName + ". Operation terminated.\n\n" + e);
        //this.isArrayLoaded = false;
    } finally {
        try {
            // Close file operations
            if (this.br != null) {
                this.br.close();
                this.fr.close();
            }
        } catch (IOException ex) {
            System.out.println("\n\n" + ex + "\n");
            ex.printStackTrace();
        }
    }
    System.out.println("\n\n");
    //return this.isArrayLoaded;
}

public void showHouses() {
    Iterator<House> itr = houseList.iterator();
    while (itr.hasNext()) {
        System.out.println(itr.next().toString());
    }
}
}

And this class…

package housetracker;

public class House {
private int address;
private String street;
private double price;
private int rooms;

public House(int address, String street, double price, int rooms) {
    this.address = address;
    this.street = street;
    this.price = price;
    this.rooms = rooms;
}

public void SetAddress (int address){
    setAddress(address);
}

private void setAddress (int address){
    this.address = address;
}

public void SetStreet (String street){
    setStreet(street);
}

private void setStreet(String street){
    this.street = street;
}

public void SetPrice (double price){
    setPrice(price);
}

private void setPrice (double price){
    this.price = price;
}

public void SetRooms(int rooms){
    setRooms(rooms);
}

private void setRooms(int rooms){
    this.rooms = rooms;
}

public int GetAddress (int address){
    address = getAddress(address);
    return address;
}

private int getAddress (int address){
    return address;
}

public String GetStreet (String street){
    street = getStreet(street);
    return street;
}

private String getStreet(String street){
    return street;
}

public double GetPrice (double price){
    price = getPrice(price);
    return price;
}

private double getPrice (double price){
    return price;
}

public int GetRooms(int rooms){
    rooms = getRooms(rooms);
    return rooms;
}

private int getRooms(int rooms){
    return rooms;
}
@Override
public String toString() {
    return address + " " + street + " " + price + " " + rooms;
}
}

  • 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-14T06:53:14+00:00Added an answer on June 14, 2026 at 6:53 am

    Can I get a delete here? I found a main method hiding in another class that wasn’t opened in my IDE. I feel like an idiot!

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

Sidebar

Related Questions

I've been developing Java with Netbeans and have been using the Run command on
I have finished developing my java application using netbeans. Now I want to give
I have a simple application using netbeans for developing and maven for building et
I'm developing Java application using NetBeans. I have 5 JTextFields and 2 JTextArea in
All Android developers I know use Eclipse. But I got used to NetBeans developing
I am developing a web application using JSF on Netbeans 7.0. I have created
I am developing in C++ using NetBeans 6.9 on Ubuntu 11.04. I have declared
I am developing C++ in NetBeans 6.7.1. When I press CTRL + space for
I am developing a Lift application using Netbeans and I have everything working apart
I have a Java EE 6 project I'm developing in NetBeans. All of the

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.