implement StudentLoader.java
This commit is contained in:
@@ -25,28 +25,26 @@ public class StudentLoader extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// TODO:
|
||||
for(String line : lines){
|
||||
|
||||
/*
|
||||
Example line:
|
||||
if( line == null || line.isBlank()) continue;
|
||||
|
||||
1001,Aryan,Computer Science,3.7
|
||||
*/
|
||||
try {
|
||||
|
||||
for (String line : lines) {
|
||||
String[] parts = line.split(",");
|
||||
|
||||
// TODO:
|
||||
// split line
|
||||
|
||||
// TODO:
|
||||
// read values
|
||||
int id = Integer.parseInt(parts[0].trim());
|
||||
String name = parts[1].trim();
|
||||
String major = parts[2].trim();
|
||||
double gpa = Double.parseDouble(parts[3].trim());
|
||||
|
||||
// TODO:
|
||||
// create Student
|
||||
|
||||
// TODO:
|
||||
// add to students list
|
||||
students.add(new Student(id, name, major, gpa));
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error parsing line: " + line);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user