I'm reading in my second text file of data, it is listed below. My first text file is reading and printing to the terminal fine.
// this is a comment, ignore
// name, usagefee, insurance, affiliationfees, then court numbers
Tennis,44,10,93,10,11,12,13,14,15,16
Squash,165,10,27,1,2,3,4
I am using the same buffer/reader as for my first text file, which is listed below.
public static ArrayList<String> readFile(String fileName) throws Exception { ArrayList<String> data = new ArrayList<String>(); BufferedReader br = new BufferedReader(new FileReader(fileName)); String line = br.readLine(); while (line != null) { String[] values = line.split(","); data.add(line); line = br.readLine(); } br.close(); return data; }
However, obviously a different readFile method. Which is below...
public Club() { try { membersList = new ArrayList<Member>(); getMemberFile(); sportsList = new ArrayList<Sport>(); getSportFile(); } catch(Throwable ex) { System.out.println(ex); } } public void getSportFile() throws Exception { ArrayList<String> sportData = FileOperations.readFile("SportData.txt"); for(String s : sportData) { sportsList.add(new Sport(s)); } }
Here is the Sport class - with the constructor (which isn't complete yet as I am know too sure on how to deal with the different lengths of data of the court numbers)
public class Sport { private String sportName; private double usageFee; private double insuranceFee; private double affiliationFee; private ArrayList<Court> courtsList; public Sport(String data) { String[] list = data.split(","); sportName = list[0]; usageFee = Double.parseDouble(list[1]); insuranceFee = Double.parseDouble(list[2]); affiliationFee = Double.parseDouble(list[3]); // haven't added the variables for the courts yet because I'm not too sure how to go about it. // same as in the constructor } // Sport constructor public Sport(String nameOfSport, double uFee, double iFee, double aFee) { this.sportName = nameOfSport; this.usageFee = uFee; this.insuranceFee = iFee; this.affiliationFee = aFee; }
I have a few problems. I have an ArrayList of courts however I am not too sure of the next step in using this in my constructor, due to be a different type and varying in length of the data.
I don't think it's parsing right or if I am even going in the right means about converting it to a 'double' for the fees. I can't even tell if it's working anyway because it's not printing to the terminal. I am receiving an error - java.lang.NumberFormatException: For input string: "ignore". Which is probably due to the above reasons.
If someone is able to please point me in the right direction. I don't expect to be given the exact answer, just a bit guidance and/or example in a different context.