The issue is just a bit of confusion about where things are happening.
In your main method you have:
Code:
public static void main(String[] args)
{
//ArrayList to store the data
ArrayList<HouseList> availableHouses = new ArrayList<HouseList>();
//Creating instance of houses.txt
System.out.println(availableHouses);
}
There are 2 issues here:
1) The HouseList class already has an ArrayList instance that it uses to store the list of houses, what you want to do is create an instance of a HouseList which will itself create the ArrayList to hold details of each House.
2) I'm fairly sure that println will not correctly print the contents of an ArrayList, although I could be wrong.
The way you would create a HouseList instance would be with:
Code:
String fileName = "name-of-file.txt";
HouseList houseList = new HouseList(fileName);
This will invoke the
constructor of the HouseList class, which contains the code for reading in from the specified file.
You should add a method to the HouseList class that will print the contents of the ArrayList so that once the HouseList instance has been created you can call that print method from the main method. An example of what that might look like is:
Code:
public void printHouses()
{
for (House house : houseList)
{
System.out.println(house);
}
}
The reason you can just pass the house instance to println is that the House class implements a
toString method. Println will call that to get the String representation of a House object. Once you have added the printHouses method to the HouseList class you should call it from your main method with a:
Does that help at all?