Hello all, well I am still working on my program and I am on the Database class. I have a load method and i want it to do the following:
1. Load data from customer.txt 2. Read in this data and put it into a Customer List (array list) in ascending order
I am kind of stuck on what to do. I know I need a scanner to read in the file and its contents. But I need it to only keep the lines that match the Customer class requirements (last name, first name, and email). What would be the best way to do all of this? Should I do a while loop or what? How do I keep creating instances of the Customer class with different names (ex. C1, C2 or something like that)?
Below is the code I have so far.. I already have a try loop set up to catch 2 possible exceptions in case the text file cannot be read or loaded. So how can I set up something that will check the parameters of a Customer object? I already have a for loop 'thought up' to use so that I can insert the new Customer objects made into the list in ascending order. The problem is creating these Objects based on the information in the text file. Thanks in advance!!
I have already created the arraylist.. i just need to read in the text file but only take in the lines that have the right elements to fit the Customer class... which are: lastName, firstName, and email. So how would I set up the scanner to read in only the lines with these 3 elements.. and then how would i create a customer object after i have recieved a line with all 3 of these elements so that i can inset this new customer object into the list??
the text file looks like this: Charlie,Zed,email@example.com
John,Smith,firstname.lastname@example.org 123 Sally,Baker,email@example.com Yo Yo, Ma ,firstname.lastname@example.org Mike,Bright,email@example.com blah,blah,blah,blah Alan,Adams,firstname.lastname@example.org Miles;Davis;email@example.com
So, I only want to take in the lines with a last name, first name, and email.. Also, i need to use a comma as the delimiter..