The following is a snippet of a txt file
Patrick Joseph
1254367
cmt101
Introduction to Computer Science
1
Computer Science
Spring
2020
B+
3
cmt102
Computer Networks
2
Computer Science
Spring
2020
A
3
Every 8 lines minus the first 2 represents an attribute of a course in a college. I am trying to sort the data into two arrayLists, course and courses. course will be an arrayList containing attributes for each course while courses will contain all the courses such that the data in courses should look something like this:
[0][0] cmt101
[0][1] Introduction to Computer Science
[0][2] 1
[0][3] Computer Science
[0][4] Spring
[0][5] 2020
[0][6] B+
[0][7] 3
[1][0] cmt102
[1][1] Computer Networks
[1][2] 2
[1][3] Computer Science
[1][4] Spring
[1][5] 2020
[1][6] A
[1][7] 3
and so on. The program should be able to iterate regardless of how many courses are added to the file while skipping the first two lines
public static ArrayList<ArrayList<String>> courses;
public static ArrayList<String> course;
public static void getCourses(){
try{
course = new ArrayList<>();
courses = new ArrayList<>();
String fileName = "C:\\Users\\myComputer\\Desktop\\file.txt";
List<String> lines = Files.readAllLines(Paths.get(fileName), Charset.defaultCharset());
for (int i = 2; i < lines.size(); i += 8){
for (int j = 2; j <= 10; j++){
course.add(lines.get(j));
}
courses.add(course);
}
}
catch(IOException io){
io.printStackTrace(System.out);
}
}
// courses is printed in another method
Any help will be appreciated