java - Adding to an object array list using a file reader -


Actually, in this situation, a company and a driver have the classes to interact with each other, this code The driver is written in. That's why I'm using a file reader to scan a text file that looks like this with one place between each line. John: Smith: Manufacturing: 6.75: 120: 444

Daughter: White: Manager: 1200.00: 111

Stan: Slim: Sales: 10000.00: 332

Betty: Boop: Design: 12.50: 50: 244

And the code is as follows. The company class addEmployee method has a string (string, string, string, double, IT, et). There is a colon in each part of the text file to be read in it, so how can I add it to an array of objects in the list. And keep on walking till everyone is not read, sorry, if it is difficult to understand my questions, if you want me to expand, tell me in the comments. I just did not want to raise the question too long.

  else if (e.getSource () == readButton) {Jfile Chooser fileChooser = new JFileChooser ("src"); If (fileChooser.showOpenDialog (zero) == JFileChooser.APPROVE_OPTION) {empFile = fileChooser.getSelectedFile (); } Scanner scan = new scanner ("empFile"); While (scanHensNext ()) {scan. Nxt () the division (":"); If (position.quals ("manager")) {c.addEmployee (fName, lName, position2, double. PRADABUL (firstmost 2), 0, integer. PRIIANT (AMPNUM2)); } And if (position angle ("sale")) {c.addEmployee (fName, lName, position 2, double. PRDA double (firstmost 2), 0, integer. PRIIN (AMPNUM2)); } Else {c.addEmployee (fName, lName, position2, double.parseDouble (firstParam2), integer. PRIINT (second step 2), integer. PRIIST (APNM2); }}    

this line:

  scan Next () Split (":") ;.   

string will return an array of s which you are not accumulating anywhere. Turn it on:

  string [] rowData = scan.next (). Split (":");   

And use every item as per your wishes, for example fill your variable for your class constructor or directly in the form of logic. Provide a sample of the former:

  fName = rowData [0]; LName = rowData [1]; Status = row data [2]; FirstParam2 = Rowdata [3]; Second paragraph 2 = row data [4]; EmpNum2 = rowData [5];    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -