Hoping someone might be able to assist me, or point me in the right direction. I have a text file with a number of entries
CUST001, John Jones, 555 0505, 19/09/1981
CUST002, PeterParker, 555 1234, 0.2
CUST003, Michael Michaels, 555 4321, 19/09/1981
etc
I have an abstract superclass with constructor and accessors for the shared properties and a subclass. i then have another class, also with constructor and accessors.
I read in each line, and split it at the "," and read this into a temp array. I then create my empty array to read into it the properties from my superclass and with the contructor, i create the various objects.
problem i have run into: regular class with constructor - this work prefectly. I print out my objects after they have been created and there they are.
My subclass though, it only returns values null, null, null I assume therefore that there is an issue with my superclass and subclass.
creating objects using the concrete class constructor:
Product[] prod = new Product[20]; BufferedReader inFile = new BufferedReader (new FileReader("product.txt")); String inputLine = inFile.readLine(); for (int i = 0; i < 6 ; i++) { String[] tmpProd = inFile.readLine().split(","); prod[i] = new Product( tmpProd[0], tmpProd[1], tmpProd[2], Float.parseFloat(tmpProd[3]), tmpProd[4].charAt(0)); }
"trying" to create objects from the superclass (Customer) and subClass (STCustomer):
Customer[] stdCust= new STCustomer[20]; BufferedReader inFileCust = new BufferedReader (new FileReader ("customer.txt")); String inputCust = inFileCust.readLine(); for (int i = 0; i < 6; i++) { String[] tmpCust = inFileCust.readLine().split(","); GregorianCalendar d = new GregorianCalendar(year, month -1, date); stdCust[i] = new STCustomer( tmpCust[0], tmpCust[1], Long.parseLong(tmpCust[2]), d);//the block to convert date works - omitted here }
Is this the correct way to create the objects?
Customer[] stdCust= new STCustomer[20];