5 Commits
Author SHA1 Message Date
Parmis_jamami 8d27896aa6 complete code 2026-05-25 21:22:34 +03:30
Parmis_jamami 067aae2ee6 implement FileManager.java 2026-05-25 21:22:06 +03:30
Parmis_jamami 133437e971 implement StudentManager.java 2026-05-25 21:21:17 +03:30
Parmis_jamami 6fc03bf1b0 implement StudentLoader.java 2026-05-25 21:20:30 +03:30
Parmis_jamami a7d2373bad implement Student.java 2026-05-25 21:18:39 +03:30
13 changed files with 146 additions and 68 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="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>
+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>
+19 -13
View File
@@ -33,31 +33,37 @@ public class Main {
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, 2 * partSize);
List<String> part3 = null;
List<String> part3 = data.subList(2 * partSize, size);
// TODO:
StudentLoader t1 = null;
StudentLoader t2 = null;
StudentLoader t1 = new StudentLoader(part1);
StudentLoader t3 = null;
StudentLoader t2 = new StudentLoader(part2);
// TODO:
StudentLoader t3 = new StudentLoader(part3);
// start()
t1.start();
t2.start();
t3.start();
// join()
t1.join();
t2.join();
t3.join();
// merge results
manager.addStudents(t1.getStudents());
manager.addStudents(t2.getStudents());
manager.addStudents(t3.getStudents());
System.out.println("Data loaded successfully.");
}
+5 -18
View File
@@ -41,30 +41,17 @@ public class Student {
@Override
public int hashCode() {
// TODO:
// Return custom hash
// Example:
// return id % 97;
return 0;
return id % 97;
}
@Override
public boolean equals(Object obj) {
// TODO:
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
// Step 1:
// Check null
// Step 2:
// Convert obj to Student
// Step 3:
// Compare IDs
return false;
Student student = (Student)obj;
return id == student.id;
}
@Override
+7 -18
View File
@@ -11,35 +11,24 @@ public class StudentManager {
public void addStudents(ArrayList<Student> newStudents) {
// TODO:
// Merge students
// Hint:
// addAll()
if(newStudents != null){
this.students.addAll(newStudents);
}
}
public Student searchStudent(int id) {
// TODO:
// Loop through students
// Compare IDs
for(Student s : students) {
if(s.getId() == id ) return s;
}
return null;
}
public boolean removeStudent(int id) {
// TODO:
// Find student
// Remove student
return false;
return students.removeIf(s -> s.getId() == id);
}
public void printStudents() {
+14 -16
View File
@@ -25,28 +25,26 @@ public class StudentLoader extends Thread {
@Override
public void run() {
// TODO:
/*
Example line:
1001,Aryan,Computer Science,3.7
*/
for(String line : lines){
// TODO:
// split line
if( line == null || line.isBlank()) continue;
// TODO:
// read values
try {
// TODO:
// create Student
String[] parts = line.split(",");
// TODO:
// add to students list
int id = Integer.parseInt(parts[0].trim());
String name = parts[1].trim();
String major = parts[2].trim();
double gpa = Double.parseDouble(parts[3].trim());
students.add(new Student(id, name, major, gpa));
} catch (Exception e) {
System.err.println("Error parsing line: " + line);
}
}
}
+1 -4
View File
@@ -18,10 +18,7 @@ public class FileManager {
while ((line = reader.readLine()) != null) {
// TODO:
// Add line to list
lines.add(line);
}
reader.close();
@@ -1,10 +1,24 @@
package lecture.multithreading.timeout;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO
Scanner scanner = new Scanner(System.in);
System.out.println("You have 10 second: ");
System.out.println("Enter your name: ");
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.setDaemon(true);
thread.start();
String name = scanner.nextLine();
System.out.println("Hello " + name);
scanner.close();
}
}
@@ -0,0 +1,19 @@
package lecture.multithreading.timeout;
public class MyRunnable implements Runnable{
@Override
public void run() {
for(int i = 1 ; i <= 10 ; i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("thread was interrupted");
}
if(i == 10) {
System.out.println("time is up. ");
System.exit(0);
}
}
}
}