WS07
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="WS-07-Multithreading-Basics-and-Hashing" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+20
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://mirror-maven.runflare.com/maven2" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="23" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
+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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-56
@@ -1,60 +1,5 @@
|
||||
1001,Dimitri,Computer Science,3.7
|
||||
1001,Ali,Computer Science,3.7
|
||||
1002,Sara,Physics,3.9
|
||||
1003,John,Mathematics,3.5
|
||||
1004,Alice,Chemistry,3.2
|
||||
1005,David,Computer Science,3.8
|
||||
1006,Emma,Biology,3.6
|
||||
1007,Tom,Physics,3.1
|
||||
1008,Lina,Mathematics,4.0
|
||||
1009,Alex,Computer Science,3.4
|
||||
1010,Sophia,Chemistry,3.8
|
||||
1011,Daniel,Physics,3.2
|
||||
1012,Mary,Biology,3.9
|
||||
1013,Kevin,Computer Science,3.5
|
||||
1014,Nina,Mathematics,3.7
|
||||
1015,Jack,Chemistry,3.0
|
||||
1016,Olivia,Computer Science,3.9
|
||||
1017,Michael,Physics,3.3
|
||||
1018,Ethan,Mathematics,3.8
|
||||
1019,Grace,Biology,3.4
|
||||
1020,Lucas,Chemistry,3.6
|
||||
1021,Emily,Computer Science,4.0
|
||||
1022,Henry,Physics,3.5
|
||||
1023,Amelia,Mathematics,3.9
|
||||
1024,Benjamin,Biology,3.1
|
||||
1025,Charlotte,Chemistry,3.7
|
||||
1026,James,Computer Science,3.2
|
||||
1027,Abigail,Physics,3.8
|
||||
1028,William,Mathematics,3.4
|
||||
1029,Ella,Biology,3.9
|
||||
1030,Noah,Chemistry,3.3
|
||||
1031,Isabella,Computer Science,3.8
|
||||
1032,Logan,Physics,3.0
|
||||
1033,Mia,Mathematics,4.0
|
||||
1034,Mason,Biology,3.5
|
||||
1035,Ava,Chemistry,3.6
|
||||
1036,Elijah,Computer Science,3.7
|
||||
1037,Harper,Physics,3.4
|
||||
1038,Jacob,Mathematics,3.2
|
||||
1039,Evelyn,Biology,3.8
|
||||
1040,Alexander,Chemistry,3.1
|
||||
1041,Scarlett,Computer Science,3.9
|
||||
1042,Sebastian,Physics,3.6
|
||||
1043,Aria,Mathematics,3.5
|
||||
1044,Matthew,Biology,3.7
|
||||
1045,Chloe,Chemistry,4.0
|
||||
1046,Samuel,Computer Science,3.3
|
||||
1047,Victoria,Physics,3.8
|
||||
1048,Joseph,Mathematics,3.1
|
||||
1049,Lily,Biology,3.9
|
||||
1050,David,Chemistry,3.4
|
||||
1051,Hannah,Computer Science,3.8
|
||||
1052,Carter,Physics,3.5
|
||||
1053,Zoey,Mathematics,3.7
|
||||
1054,Owen,Biology,3.2
|
||||
1055,Penelope,Chemistry,3.9
|
||||
1056,Wyatt,Computer Science,4.0
|
||||
1057,Riley,Physics,3.3
|
||||
1058,Luke,Mathematics,3.6
|
||||
1059,Layla,Biology,3.4
|
||||
1060,Gabriel,Chemistry,3.8
|
||||
Reference in New Issue
Block a user