Array help needed

I am having problems with a code that I have to create this is what is being asked of me to do

1. Reads input for each customer object from a file. (each separated by tab char):

firstNamelastNamecitystatezip

2. Create and submit your data file; name it customerData.txt The name of the data file should be a command line argument.3. Create an array of size 20 and store each object created in 1 above in the array. You will need to keep track of the end of the array, so it can hold a variable number of customers.4. Place 10 customer objects in your array.

5. print

I am not sure what I am doing wrong.

Here is my .txt

10

Dillin Jake York PA 17409

Valdir John Chicago IL 98098

Morphy Bob Harrisburg PA 73829

Spears Johnathan Chicago IL 09182

Simpson Bloo Los Angeles CA 94840

Griffin Taylor York IL 49283

Cartmen Eric Philadelphia PA 28192

Connaly Teds Springfield IL 12930

Marsh Stan Miami FL 48392

William Thomas Reno NV 39029

and this is the code:

public class TestCustomer {

publicstaticvoid main (String[] args)throws FileNotFoundException{

Scanner scan =new Scanner (new File ("customerData.txt"));

Customer[] customer;

customer =new Customer [40];

int numLines = scan.nextInt();

for (int i = 0; i < numLines; i++){

String fName = scan.next();

String lName = scan.next();

String city = scan.next();

String state = scan.next();

int zip= scan.nextInt();

System.out.println(fName +", "+ lName+"" + city +""+ state +""+ zip);

Customer newObj = Customer(fName,lName,city,state,zip);

Customer[i]=newObj;

}

}

}

[2382 byte] By [JoWilliam01a] at [2007-10-2 20:34:48]
# 1
What problems are you having? Be specific.
jverda at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 2
The problem that I have is that I can not understand how to add objects from the file into the array.
JoWilliam01a at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 3
http://java.sun.com/docs/books/tutorial/java/data/arrays.html
jverda at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 4

I read this before but my problem is the fact that I dont understand how to use the information from a file. That is while I have the Customer[] array and this is where I have problems plus the this problem includes a class

class Customer{

private String firstName;

private String lastName;

private String city;

private String state;

private int zip;

public Customer(){

firstName = " ";

lastName = " ";

city = " ";

state = " ";

zip = 0;

}

public Customer(String f, String l, String c, String s, int z){

this.firstName = f;

this.lastName = l;

this.city = c;

this.state = s;

this.zip = z;

System.out.println(this.toString());

}

public String getFirst(){

return firstName;

}

public String getLast(){

return lastName;

}

public String getCity(){

return city;

}

public String getState(){

return state;

}

public int getZip(){

return zip;

}

public String toString(){

return getFirst() + ", " + getLast() + "" + getCity() + ""

+ getState() + "" + getZip();

}

}

JoWilliam01a at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 5

> I read this before but my problem is the fact that I

> dont understand how to use the information from a

> file.

http://java.sun.com/docs/books/tutorial/essential/io/index.html

> this is where I have problems plus the this problem

> includes a class

Okay, so there's a class. Why is that a problem? You can't write Java code without classes. What part about the class are you having trouble with.

jverda at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 6
My issue is putting the information from the file that I read into the class from the array. I am confused, do I have to put the information into the array that is based off of the class or just trying to store the objects into the array
JoWilliam01a at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 7
Per your initial message, sounds like you need to store the object in the array. Also the following line of code Customer newObj = Customer(fName,lName,city,state,zip);should beCustomer newObj = new Customer(fName,lName,city,state,zip);
SanMana at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 8
That is true I have to store the objects in the array but since this is the first time I do a code with information from a file...I do not know how to this
JoWilliam01a at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 9

Whether it comes from a file or not makes no difference.

Read a line from a file.

Use the data in that line to populate an object.

Put that object (technically, a reference to the object) into an array.

What exactly are you having trouble with? You're really not being very specific. The details on how to do all of the above are in the two links I provided. If you go through those tutorials and are still stuck, post very specific details about what the problem is.

jverda at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 10
Thank you SanMan...I didn't realize that I forgot to put in the new in that part of the code...now I am no longer getting errors
JoWilliam01a at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...
# 11
I get it now...thank you both so much for your help
JoWilliam01a at 2007-7-13 23:17:58 > top of Java-index,Java Essentials,Java Programming...