Hey all, working on trying to read in a text file so that I can split it into multiple arrays. Text file looks like this
Amy Adams 10111 97 86 78 95 Ben Barr 20222 89 81 73 87 Carla Carr 30333 79 71 63 77 Don Davis 40444 69 62 58 67 Edna Eaton 50555 63 51 62 48
The name, the student id, and a set of their 4 grades must be split into seperate arrays so that they can be used later to calculate avg's and so on. I'm having trouble getting them to go into different arrays.
This is what I have so far.
import java.io.*; public class Program2 { public static void main(String[] args) throws IOException { File dataFile = new File("G:\\COSC 1337\\Handouts 6-14\\Student Data.txt"); BufferedReader br = new BufferedReader(new FileReader(dataFile)); String str; String[] names = new String[5]; int[] grades = new int[20]; String[] studentID = new String[20]; for (int i = 0; i < 5; i++) { str = br.readLine(); names[i] = str; str = br.readLine(); studentID[i] = str; str = br.readLine(); grades[i] = Integer.parseInt(str); }
I keep getting a numberFormatexception, I assume from trying to parse the string for grades... but I'm unsure how to go about getting all the grades into an array, if everything else is only strings.