Author SHA1 Message Date
reyhne a6bedb3b8a Merge pull request 'WS 07' (#1) from develop into main
Reviewed-on: Arshida_0/WS-07-Multithreading-Basics-and-Hashing-Arshida#1
2026-07-16 18:01:26 +00:00
Arshida_0 e50d722242 WS 07 2026-05-25 17:06:40 +04:30
11 changed files with 148 additions and 11 deletions
+10
View File
@@ -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/
+13
View File
@@ -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>
+7
View File
@@ -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>
+20
View File
@@ -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="Central Repository" />
<option name="url" value="https://maven.devneeds.ir/" />
</remote-repository>
<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>
</component>
</project>
+12
View File
@@ -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="25" project-jdk-type="JavaSDK" />
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+42 -7
View File
@@ -1,9 +1,11 @@
package dev; package dev;
import dev.model.Student;
import dev.service.StudentManager; import dev.service.StudentManager;
import dev.thread.StudentLoader; import dev.thread.StudentLoader;
import dev.utils.FileManager; import dev.utils.FileManager;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
@@ -37,28 +39,56 @@ public class Main {
// Split data into 3 parts // Split data into 3 parts
List<String> part1 = null; int sp1;
switch (data.size() % 3) {
case 1: {
sp1 = (data.size()-1)/3;
break;
}
case 2: {
sp1 = (data.size()-2)/3;
break;
}
default: {
sp1 = data.size()/3;
break;
}
}
int sp2 = sp1 * 2;
List<String> part2 = null; List<String> part1 = data.subList(0, sp1);
List<String> part3 = null; List<String> part2 = data.subList(sp1, sp2);
List<String> part3 = data.subList(sp2, 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:
// start() // start()
t3.start();
t2.start();
t1.start();
// join() // join()
t3.join();
t2.join();
t1.join();
// merge results // merge results
manager.addStudents(t1.getStudents());
manager.addStudents(t2.getStudents());
manager.addStudents(t3.getStudents());
} }
case 2 -> { case 2 -> {
@@ -79,7 +109,12 @@ public class Main {
boolean removed = manager.removeStudent(id); boolean removed = manager.removeStudent(id);
System.out.println(removed); String res = "The student with id: " + id;
if (removed) res += "is removed successfully. ";
else res += "is not found. ";
System.out.println(res);
} }
+6 -4
View File
@@ -45,9 +45,7 @@ public class Student {
// Return custom hash // Return custom hash
// Example: // Example:
// return id % 97; return id % 97;
return 0;
} }
@Override @Override
@@ -64,7 +62,11 @@ public class Student {
// Step 3: // Step 3:
// Compare IDs // Compare IDs
return false; if (obj == this) return true;
if (obj == null || obj.getClass() != getClass()) return false;
Student student = (Student) obj;
return student.getId() == id;
} }
@Override @Override
@@ -2,6 +2,7 @@ package dev.service;
import dev.model.Student; import dev.model.Student;
import java.sql.Struct;
import java.util.ArrayList; import java.util.ArrayList;
@@ -18,6 +19,7 @@ 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 student : students) {
if (student.getId() == id) {
return student;
}
}
return null; return null;
} }
@@ -39,6 +47,13 @@ public class StudentManager {
// Remove student // Remove student
for (Student student : students) {
if (student.getId() == id) {
students.remove(student);
return true;
}
}
return false; return false;
} }
@@ -47,6 +47,21 @@ public class StudentLoader extends Thread {
// TODO: // TODO:
// add to students list // add to students list
String[] data = line.split(",");
try {
int id = Integer.parseInt(data[0]);
String name = data[1];
String major = data[2];
double gpa = Double.parseDouble(data[3]);
Student student = new Student(id, name, major, gpa);
students.add(student);
}
catch (Exception e) {
//...
}
} }
} }
+2
View File
@@ -22,6 +22,8 @@ public class FileManager {
// Add line to list // Add line to list
lines.add(line);
} }
reader.close(); reader.close();