Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f09b91d8c2 |
@@ -37,19 +37,19 @@ public class Main {
|
|||||||
|
|
||||||
// Split data into 3 parts
|
// Split data into 3 parts
|
||||||
|
|
||||||
List<String> part1 = null;
|
List<String> part1 = data.subList(0, data.size()*35/100);
|
||||||
|
|
||||||
List<String> part2 = null;
|
List<String> part2 = data.subList(data.size()*35/100, data.size()*7/10);
|
||||||
|
|
||||||
List<String> part3 = null;
|
List<String> part3 = data.subList(data.size()*7/10, data.size());
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
||||||
StudentLoader t1 = null;
|
StudentLoader t1 = new StudentLoader(part1);
|
||||||
|
|
||||||
StudentLoader t2 = null;
|
StudentLoader t2 = new StudentLoader(part2);
|
||||||
|
|
||||||
StudentLoader t3 = null;
|
StudentLoader t3 = new StudentLoader(part3);
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
||||||
@@ -57,8 +57,20 @@ public class Main {
|
|||||||
|
|
||||||
// join()
|
// join()
|
||||||
|
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
t3.start();
|
||||||
|
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
t3.join();
|
||||||
|
|
||||||
// merge results
|
// merge results
|
||||||
|
|
||||||
|
manager.addStudents(t1.getStudents());
|
||||||
|
manager.addStudents(t2.getStudents());
|
||||||
|
manager.addStudents(t3.getStudents());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2 -> {
|
case 2 -> {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class Student {
|
|||||||
// Example:
|
// Example:
|
||||||
// return id % 97;
|
// return id % 97;
|
||||||
|
|
||||||
return 0;
|
return id % 97;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,7 +64,12 @@ public class Student {
|
|||||||
// Step 3:
|
// Step 3:
|
||||||
// Compare IDs
|
// Compare IDs
|
||||||
|
|
||||||
|
if (obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Student st = (Student) obj;
|
||||||
|
|
||||||
|
return this.getId() == st.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ public class StudentManager {
|
|||||||
// Hint:
|
// Hint:
|
||||||
// addAll()
|
// addAll()
|
||||||
|
|
||||||
|
students.addAll(newStudents);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Student searchStudent(int id) {
|
public Student searchStudent(int id) {
|
||||||
@@ -28,6 +30,12 @@ public class StudentManager {
|
|||||||
|
|
||||||
// Compare IDs
|
// Compare IDs
|
||||||
|
|
||||||
|
for (Student st : students) {
|
||||||
|
|
||||||
|
if (st.getId() == id)
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +47,15 @@ public class StudentManager {
|
|||||||
|
|
||||||
// Remove student
|
// Remove student
|
||||||
|
|
||||||
|
for (Student st : students) {
|
||||||
|
|
||||||
|
if (st.getId() == id) {
|
||||||
|
students.remove(st);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,15 +38,25 @@ public class StudentLoader extends Thread {
|
|||||||
// TODO:
|
// TODO:
|
||||||
// split line
|
// split line
|
||||||
|
|
||||||
|
List<String> parts = List.of(line.split(","));
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// read values
|
// read values
|
||||||
|
|
||||||
|
int id = Integer.parseInt(parts.get(0));
|
||||||
|
String name = parts.get(1);
|
||||||
|
String major = parts.get(2);
|
||||||
|
double gpa = Double.parseDouble(parts.get(3));
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// create Student
|
// create Student
|
||||||
|
|
||||||
|
Student currentStudent = new Student(id, name, major, gpa);
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// add to students list
|
// add to students list
|
||||||
|
|
||||||
|
students.add(currentStudent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ public class FileManager {
|
|||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
|
||||||
// TODO:
|
lines.add(line);
|
||||||
|
|
||||||
// Add line to list
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user