Develop #1
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://maven.myket.ir" />
|
||||||
|
</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="25" 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>
|
||||||
+26
-20
@@ -4,6 +4,7 @@ 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;
|
||||||
|
|
||||||
@@ -33,32 +34,37 @@ public class Main {
|
|||||||
|
|
||||||
List<String> data = FileManager.loadStudents("students.txt");
|
List<String> data = FileManager.loadStudents("students.txt");
|
||||||
|
|
||||||
// TODO:
|
ArrayList<String> part1 = new ArrayList<>();
|
||||||
|
ArrayList<String> part2 = new ArrayList<>();
|
||||||
|
ArrayList<String> part3 = new ArrayList<>();
|
||||||
|
|
||||||
// Split data into 3 parts
|
for(int i=0; i<data.size(); i++) {
|
||||||
|
if (i%3 == 0) {
|
||||||
|
part1.add(data.get(i));
|
||||||
|
} else if (i%3 == 1) {
|
||||||
|
part2.add(data.get(i));
|
||||||
|
} else {
|
||||||
|
part3.add(data.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<String> part1 = null;
|
StudentLoader t1 = new StudentLoader(part1);
|
||||||
|
StudentLoader t2 = new StudentLoader(part2);
|
||||||
|
StudentLoader t3 = new StudentLoader(part3);
|
||||||
|
|
||||||
List<String> part2 = null;
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
t3.start();
|
||||||
|
|
||||||
List<String> part3 = null;
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
t3.join();
|
||||||
|
|
||||||
// TODO:
|
manager.addStudents(t1.getStudents());
|
||||||
|
manager.addStudents(t2.getStudents());
|
||||||
StudentLoader t1 = null;
|
manager.addStudents(t3.getStudents());
|
||||||
|
|
||||||
StudentLoader t2 = null;
|
|
||||||
|
|
||||||
StudentLoader t3 = null;
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
|
|
||||||
// start()
|
|
||||||
|
|
||||||
// join()
|
|
||||||
|
|
||||||
// merge results
|
|
||||||
|
|
||||||
|
System.out.println("Students loaded successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2 -> {
|
case 2 -> {
|
||||||
|
|||||||
@@ -40,31 +40,20 @@ public class Student {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
return this.getId() % 97;
|
||||||
// TODO:
|
|
||||||
// Return custom hash
|
|
||||||
|
|
||||||
// Example:
|
|
||||||
// return id % 97;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == null) return false;
|
||||||
|
|
||||||
// TODO:
|
if (this == obj) return true;
|
||||||
|
|
||||||
// Step 1:
|
if (this.getClass() != obj.getClass()) return false;
|
||||||
// Check null
|
|
||||||
|
|
||||||
// Step 2:
|
Student other = (Student) obj;
|
||||||
// Convert obj to Student
|
|
||||||
|
|
||||||
// Step 3:
|
return this.id == other.id;
|
||||||
// Compare IDs
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,34 +10,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) {
|
||||||
|
if (newStudents != null && !newStudents.isEmpty()) {
|
||||||
// TODO:
|
students.addAll(newStudents);
|
||||||
|
}
|
||||||
// Merge students
|
|
||||||
|
|
||||||
// Hint:
|
|
||||||
// addAll()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Student searchStudent(int id) {
|
public Student searchStudent(int id) {
|
||||||
|
for (Student student: students) {
|
||||||
// TODO:
|
if (student.getId() == id) {
|
||||||
|
return student;
|
||||||
// Loop through students
|
}
|
||||||
|
}
|
||||||
// Compare IDs
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeStudent(int id) {
|
public boolean removeStudent(int id) {
|
||||||
|
Student s = searchStudent(id);
|
||||||
|
|
||||||
// TODO:
|
if (s != null) {
|
||||||
|
students.remove(s);
|
||||||
// Find student
|
return true;
|
||||||
|
}
|
||||||
// Remove student
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,35 +24,27 @@ 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) {
|
||||||
|
try {
|
||||||
|
String[] parts = line.split(",");
|
||||||
|
|
||||||
// TODO:
|
if(parts.length == 4) {
|
||||||
// split line
|
int id = Integer.parseInt(parts[0].trim());
|
||||||
|
String name = parts[1].trim();
|
||||||
|
String major = parts[2].trim();
|
||||||
|
double gpa = Double.parseDouble(parts[3].trim());
|
||||||
|
|
||||||
// TODO:
|
Student student = new Student(id,name,major,gpa);
|
||||||
// read values
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// create Student
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// add to students list
|
|
||||||
|
|
||||||
|
students.add(student);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Student> getStudents() {
|
public ArrayList<Student> getStudents() {
|
||||||
|
|
||||||
return students;
|
return students;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,9 @@ public class FileManager {
|
|||||||
String line;
|
String line;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (!line.trim().isEmpty()) {
|
||||||
// TODO:
|
lines.add(line);
|
||||||
|
}
|
||||||
// Add line to list
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user