Can't fill the array with the object?
This is frustrating...My array keeps getting filled with the address object, and not the contents of the object, like so:
http://i433.photobucket.com/albums/qq53/Clerek/java.png
I can't figure out what I'm doing wrong...
Main:
Code:
import java.util.Scanner;
import java.io.*;
public class CSCD210Lab9
{
public static void main(String [] args)throws IOException
{
int total, choice;
Address [] addresses = null;
Scanner fin = new Scanner(new File("addresses.txt"));
/* An address in the file is
street - String
city - String
state - String
zip - int
*/
total = FileUtilLab9.count(fin);
fin.close();
fin = new Scanner(new File("addresses.txt"));
addresses = FileUtilLab9.fillArray(fin, total);
fin.close();
fillArray:
Code:
public static Address [] fillArray(Scanner fin, int total)
{
String st = fin.nextLine();
String ci = fin.nextLine();
String sta = fin.nextLine();
int z = Integer.parseInt(fin.nextLine());
//Address[] myAddress = new Address[total];
Address temp = new Address(st, ci, sta, z);
Address[] myAddress = new Address[total];
for(int x = 0; x < myAddress.length; x++)
{
myAddress[x] = temp;
}//end for loop
return myAddress;
*/
}//end fillArray
Address:
Code:
public class Address
{
private String street = null;
private String city = null;
private String state = null;
private int zip = 0;
public Address(String st, String ci, String sta, int z)
{
this.street = st;
this.city = ci;
this.state = sta;
this.zip = z;
}//end Address
}//end class