Author SHA1 Message Date
HesamGhazi 41bf593d4c ws-07 is complete 2026-06-28 17:30:29 +03:30
HesamGhazi b9c76e81cd WS-07 is complete 2026-06-28 17:22:15 +03:30
16 changed files with 154 additions and 80 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://repo.maven.apache.org/maven2" />
</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>
+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/
+1
View File
@@ -0,0 +1 @@
Main.java
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/java.iml" filepath="$PROJECT_DIR$/.idea/java.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>
+22 -17
View File
@@ -1,4 +1,8 @@
package dev; package dev;
/**
* @Author Hesam Ghazi
* Student Number: 403222015
*/
import dev.service.StudentManager; import dev.service.StudentManager;
import dev.thread.StudentLoader; import dev.thread.StudentLoader;
@@ -33,32 +37,33 @@ public class Main {
List<String> data = FileManager.loadStudents("students.txt"); List<String> data = FileManager.loadStudents("students.txt");
// TODO: int size = data.size();
// Split data into 3 parts int partSize = size / 3;
List<String> part1 = null; List<String> part1 = data.subList(0, partSize);
List<String> part2 = null; List<String> part2 = data.subList(partSize, partSize * 2);
List<String> part3 = null; List<String> part3 = data.subList(partSize * 2, size);
// TODO: StudentLoader t1 = new StudentLoader(part1);
StudentLoader t2 = new StudentLoader(part2);
StudentLoader t3 = new StudentLoader(part3);
StudentLoader t1 = null; t1.start();
t2.start();
t3.start();
StudentLoader t2 = null; t1.join();
t2.join();
t3.join();
StudentLoader t3 = null; manager.addStudents(t1.getStudents());
manager.addStudents(t2.getStudents());
// TODO: manager.addStudents(t3.getStudents());
// start()
// join()
// merge results
System.out.println("Students loaded successfully.");
} }
case 2 -> { case 2 -> {
+8 -21
View File
@@ -21,7 +21,7 @@ public class Student {
this.major = major; this.major = major;
this.gpa = gpa; this.gpa = gpa;
} }
// Hesam Ghazi
public int getId() { public int getId() {
return id; return id;
} }
@@ -40,36 +40,24 @@ public class Student {
@Override @Override
public int hashCode() { public int hashCode() {
return id % 97;
// TODO:
// Return custom hash
// Example:
// return id % 97;
return 0;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
// TODO: if (obj == null)
return false;
// Step 1: if (!(obj instanceof Student))
// Check null return false;
// Step 2: Student other = (Student) obj;
// Convert obj to Student
// Step 3: return this.id == other.id;
// Compare IDs
return false;
} }
@Override @Override
public String toString() { public String toString() {
return "Student{" + return "Student{" +
"id=" + id + "id=" + id +
", name='" + name + '\'' + ", name='" + name + '\'' +
@@ -77,5 +65,4 @@ public class Student {
", gpa=" + gpa + ", gpa=" + gpa +
'}'; '}';
} }
} }
+12 -19
View File
@@ -1,7 +1,6 @@
package dev.service; package dev.service;
import dev.model.Student; import dev.model.Student;
import java.util.ArrayList; import java.util.ArrayList;
@@ -10,34 +9,28 @@ public class StudentManager {
private final ArrayList<Student> students = new ArrayList<>(); private final ArrayList<Student> students = new ArrayList<>();
public void addStudents(ArrayList<Student> newStudents) { public void addStudents(ArrayList<Student> newStudents) {
students.addAll(newStudents);
// TODO:
// Merge students
// Hint:
// addAll()
} }
public Student searchStudent(int id) { public Student searchStudent(int id) {
// TODO: for (Student student : students) {
if (student.getId() == id) {
// Loop through students return student;
}
// Compare IDs }
return null; return null;
} }
public boolean removeStudent(int id) { public boolean removeStudent(int id) {
// TODO: Student student = searchStudent(id);
// Find student if (student != null) {
students.remove(student);
// Remove student return true;
}
return false; return false;
} }
+7 -18
View File
@@ -25,30 +25,19 @@ public class StudentLoader extends Thread {
@Override @Override
public void run() { public void run() {
// TODO:
/*
Example line:
1001,Aryan,Computer Science,3.7
*/
for (String line : lines) { for (String line : lines) {
// TODO: String[] parts = line.split(",");
// split line
// TODO: int id = Integer.parseInt(parts[0]);
// read values String name = parts[1];
String major = parts[2];
double gpa = Double.parseDouble(parts[3]);
// TODO: Student student = new Student(id, name, major, gpa);
// create Student
// TODO:
// add to students list
students.add(student);
} }
} }
public ArrayList<Student> getStudents() { public ArrayList<Student> getStudents() {
+3 -5
View File
@@ -16,14 +16,12 @@ public class FileManager {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
lines.add(line);
// TODO:
// Add line to list
} }
reader.close(); reader.close();
return lines; return lines;