WS07
This commit is contained in:
+19
-13
@@ -37,27 +37,33 @@ public class Main {
|
||||
|
||||
// Split data into 3 parts
|
||||
|
||||
List<String> part1 = null;
|
||||
int size = data.size();
|
||||
int chunk = (size + 2) / 3;
|
||||
|
||||
List<String> part2 = null;
|
||||
List<String> part1 = data.subList(0, Math.min(chunk, size));
|
||||
|
||||
List<String> part3 = null;
|
||||
List<String> part2 = data.subList(Math.min(chunk, size), Math.min(2 * chunk, size));
|
||||
|
||||
List<String> part3 = data.subList(Math.min(2 * chunk, size), size);
|
||||
|
||||
// TODO:
|
||||
|
||||
StudentLoader t1 = null;
|
||||
|
||||
StudentLoader t2 = null;
|
||||
|
||||
StudentLoader t3 = null;
|
||||
StudentLoader t1 = new StudentLoader(part1);
|
||||
StudentLoader t2 = new StudentLoader(part2);
|
||||
StudentLoader t3 = new StudentLoader(part3);
|
||||
|
||||
// TODO:
|
||||
t1.start();
|
||||
t2.start();
|
||||
t3.start();
|
||||
|
||||
// start()
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
|
||||
// join()
|
||||
|
||||
// merge results
|
||||
manager.addStudents(t1.getStudents());
|
||||
manager.addStudents(t2.getStudents());
|
||||
manager.addStudents(t3.getStudents());
|
||||
|
||||
}
|
||||
|
||||
@@ -96,4 +102,4 @@ public class Main {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Student {
|
||||
// Example:
|
||||
// return id % 97;
|
||||
|
||||
return 0;
|
||||
return id % 97;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +64,9 @@ public class Student {
|
||||
// Step 3:
|
||||
// Compare IDs
|
||||
|
||||
return false;
|
||||
if (obj == null) return false;
|
||||
Student other = (Student) obj;
|
||||
return this.id == other.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,4 +80,4 @@ public class Student {
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ public class StudentManager {
|
||||
// Hint:
|
||||
// addAll()
|
||||
|
||||
students.addAll(newStudents);
|
||||
|
||||
}
|
||||
|
||||
public Student searchStudent(int id) {
|
||||
@@ -28,6 +30,12 @@ public class StudentManager {
|
||||
|
||||
// Compare IDs
|
||||
|
||||
for (Student student : students) {
|
||||
if (student.getId() == id) {
|
||||
return student;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -39,6 +47,13 @@ public class StudentManager {
|
||||
|
||||
// Remove student
|
||||
|
||||
for (Student student : students) {
|
||||
if (student.getId() == id) {
|
||||
students.remove(student);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -52,4 +67,4 @@ public class StudentManager {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,26 +27,30 @@ public class StudentLoader extends Thread {
|
||||
|
||||
// TODO:
|
||||
|
||||
/*
|
||||
Example line:
|
||||
|
||||
1001,Aryan,Computer Science,3.7
|
||||
*/
|
||||
|
||||
for (String line : lines) {
|
||||
|
||||
// TODO:
|
||||
// split line
|
||||
String[] parts = line.split(",");
|
||||
|
||||
// TODO:
|
||||
// read values
|
||||
|
||||
int id = Integer.parseInt(parts[0]);
|
||||
String name = parts[1];
|
||||
String major = parts[2];
|
||||
double gpa = Double.parseDouble(parts[3]);
|
||||
|
||||
// TODO:
|
||||
// create Student
|
||||
|
||||
Student student = new Student(id, name, major, gpa);
|
||||
|
||||
// TODO:
|
||||
// add to students list
|
||||
|
||||
students.add(student);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,4 +60,4 @@ public class StudentLoader extends Thread {
|
||||
return students;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,10 @@ public class FileManager {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
|
||||
// TODO:
|
||||
|
||||
// Add line to list
|
||||
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user