and this is where you are stuck.
if this is correct,
1) if the customer data is saved into a file then you should be creating a Customer object
2) it probably would be better to use an ArrayList rather than an array,
so you can easily add new Customers. If the customers are to have a CustomerID,
a HashMap would be better
this is roughly the changes to your code
to get this to work, create a class Variable
Map customers = new HashMap();
create up a Customer class
you need to break up the customer's data from the file (after reading it into 'line')
String's split() will do that for you - it returns an array
String bits = line.split("\\|");\\where "\\|" is a regex for '|', a common delimeter
Creating the customer object
Customer cust = new Customer(bits,bits,bits);
(probably would check bits.length to ensure it is = 3)
add the customer object to the hashmap
customers.put(bits,cust);//where bits is the customersID, or 'key' for the hashmap
put it all together and you should have it
Originally posted by John Saito:
thanks for the help so far. what i am trying to do is, to get this program to read in any names stored in a txt file (Customer List.txt) and insert them into the array. this program will allow users to add to a list, search the list for a name and delete from the list. I want to add to it buy being able to save and read from a file. It would be better if the program could read the file automatically when it is first ran. hope this clears up what i am trying to do.
Okay, that helps. However, we also need to know what the program ACTUALLY does. Perhaps you can describe what you do to run the program. It looks like you provide a menu to the user. Which of these choices causes the problems? Details such as these will help you (and us) to understand which parts of your code you need to focus on.
I know its not complete but im clueless where to go from here.
this is the code for saving the list to a .txt.:
this outputs "OneWayNoRepeatsList@757aef" in the text file. how do i get the records that are stored in the array to save into the file.
What is this variable called next? Apparently it is an array, but an array of what? From the output you recieve I guess it is an array of OneWayNoRepeatsList objects. What does this class do? From the name, I can only guess that it is a list of some kind? Does it store a list of Customer objects or something similar? If this is the case, then why do you have an array of these lists? Do you need to keep multiple customer lists? This is just something to think about even though it's not related to your exact question.
So assuming that OneWayNoRepeatsList is a list of Customer objects, you need to figure out how to iterate through the Customers in the list. In other words, you need to get one Customer at a time and write it to the file. For each Customer object, you will need to get the data that you want to write to the file. It sounds like you will need at least one loop here. You might also want to find a way to break this up into a couple of different methods. For example, one method might write a single Customer object to a given OutputStream. Then another method will repeatedly call the first method with different Customer objects.
Does this help at all? Let us know how things work out for you.