Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56414f7604 | ||
|
|
d9bc9d8eb9 |
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="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>
|
||||
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>
|
||||
+36
-14
@@ -11,11 +11,14 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
boolean once = true;
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
StudentManager manager = new StudentManager();
|
||||
|
||||
while (true) {
|
||||
System.out.println("==================================");
|
||||
|
||||
System.out.println("""
|
||||
1.Load students
|
||||
@@ -23,41 +26,59 @@ public class Main {
|
||||
3.Remove student
|
||||
4.Print students
|
||||
5.Exit
|
||||
Chose:
|
||||
""");
|
||||
|
||||
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
|
||||
switch (choice) {
|
||||
|
||||
case 1 -> {
|
||||
|
||||
List<String> data = FileManager.loadStudents("students.txt");
|
||||
if(once){
|
||||
List<String> data = FileManager.loadStudents("students.txt");
|
||||
|
||||
// TODO:
|
||||
int n = data.size();
|
||||
|
||||
// Split data into 3 parts
|
||||
List<String> part1 = data.subList(0 , n/3 );
|
||||
|
||||
List<String> part1 = null;
|
||||
List<String> part2 = data.subList(n/3 , (2*n)/3);
|
||||
|
||||
List<String> part2 = null;
|
||||
List<String> part3 = data.subList((2*n)/3 , n);
|
||||
|
||||
List<String> part3 = null;
|
||||
|
||||
// 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:
|
||||
t1.start();
|
||||
t2.start();
|
||||
t3.start();
|
||||
|
||||
// start()
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
|
||||
// join()
|
||||
manager.addStudents(t1.getStudents());
|
||||
manager.addStudents(t2.getStudents());
|
||||
manager.addStudents(t3.getStudents());
|
||||
|
||||
System.out.println("Loading Done");
|
||||
once = false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
System.out.println("you have load students befor");
|
||||
}
|
||||
|
||||
// merge results
|
||||
|
||||
}
|
||||
|
||||
@@ -87,6 +108,7 @@ public class Main {
|
||||
manager.printStudents();
|
||||
|
||||
case 5 -> {
|
||||
System.out.println("Good by");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,30 +41,27 @@ public class Student {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
// TODO:
|
||||
// Return custom hash
|
||||
return id % 97;
|
||||
|
||||
// Example:
|
||||
// return id % 97;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
// TODO:
|
||||
if(obj == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 1:
|
||||
// Check null
|
||||
Student std = (Student) obj;
|
||||
|
||||
// Step 2:
|
||||
// Convert obj to Student
|
||||
if(std.hashCode() == this.hashCode()){
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 3:
|
||||
// Compare IDs
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.service;
|
||||
|
||||
import dev.model.Student;
|
||||
import dev.utils.FileManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -11,35 +12,38 @@ public class StudentManager {
|
||||
|
||||
public void addStudents(ArrayList<Student> newStudents) {
|
||||
|
||||
// TODO:
|
||||
|
||||
// Merge students
|
||||
|
||||
// Hint:
|
||||
// addAll()
|
||||
this.students.addAll(newStudents);
|
||||
|
||||
}
|
||||
|
||||
public Student searchStudent(int id) {
|
||||
|
||||
// TODO:
|
||||
|
||||
// Loop through students
|
||||
|
||||
// Compare IDs
|
||||
for(Student st : students){
|
||||
if(st.getId() == id){
|
||||
return st;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean removeStudent(int id) {
|
||||
|
||||
// TODO:
|
||||
Student removeable = null;
|
||||
|
||||
// Find student
|
||||
for(Student st: students){
|
||||
if(st.getId() == id){
|
||||
removeable = st;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove student
|
||||
if(removeable!= null){
|
||||
students.remove(removeable);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public void printStudents() {
|
||||
|
||||
@@ -25,27 +25,15 @@ 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
|
||||
String[] data = line.split(",");
|
||||
|
||||
// TODO:
|
||||
// read values
|
||||
Student mystd = new Student(Integer.parseInt(data[0]) , data[1] ,
|
||||
data[2] , Double.parseDouble(data[3]));
|
||||
|
||||
// TODO:
|
||||
// create Student
|
||||
students.add(mystd);
|
||||
|
||||
// TODO:
|
||||
// add to students list
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@ public class FileManager {
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
|
||||
// TODO:
|
||||
|
||||
// Add line to list
|
||||
lines.add(line);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user