|
|
@ -1,5 +1,7 @@ |
|
|
|
package org.example; |
|
|
|
import java.io.*; |
|
|
|
import java.util.List; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -111,4 +113,25 @@ public class Course { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static List<Course> readFromFile(String filename) { |
|
|
|
List<Course> courses = new ArrayList<>(); |
|
|
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { |
|
|
|
String line; |
|
|
|
while ((line = reader.readLine()) != null) { |
|
|
|
String courseName = line; |
|
|
|
String courseCode = reader.readLine(); |
|
|
|
int credits = Integer.parseInt(reader.readLine()); |
|
|
|
// Read any other fields you saved |
|
|
|
Course course = new Course(courseName, courseCode, credits); |
|
|
|
courses.add(course); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
return courses; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |