From c595a9bfc4f64f1aa352ef0c51980dd859a294e9 Mon Sep 17 00:00:00 2001 From: MahsaMv <156520622+MahsaMv@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:16:33 +0330 Subject: [PATCH 1/6] Shuffle --- Shuffle | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Shuffle diff --git a/Shuffle b/Shuffle new file mode 100644 index 0000000..eb68aa9 --- /dev/null +++ b/Shuffle @@ -0,0 +1,13 @@ +import java.util.LinkedList; +import java.util.Collections; +public class Main { + public static void main(String[] args) { + LinkedList linkedList = new LinkedList<>(); + linkedList.add(1); + linkedList.add(2); + linkedList.add(3); + linkedList.add(4); + Collections.shuffle(linkedList); + System.out.println(linkedList); + } +} From 626159fc4b865c63f69ca519ede496609ea89521 Mon Sep 17 00:00:00 2001 From: MahsaMv <156520622+MahsaMv@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:17:40 +0330 Subject: [PATCH 2/6] Update Detective.java --- Detective.java | 71 ++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/Detective.java b/Detective.java index 5707416..a1c074a 100644 --- a/Detective.java +++ b/Detective.java @@ -1,35 +1,44 @@ - import java.util.ArrayList; class ToDos { - - public static void main(String[] args) { - - // Sherlock - ArrayList sherlocksToDos = new ArrayList(); - - sherlocksToDos.add("visit the crime scene"); - sherlocksToDos.add("play violin"); - sherlocksToDos.add("interview suspects"); - sherlocksToDos.add("solve the case"); - sherlocksToDos.add("apprehend the criminal"); - - // Poirot - ArrayList poirotsToDos = new ArrayList(); - - poirotsToDos.add("visit the crime scene"); - poirotsToDos.add("interview suspects"); - poirotsToDos.add("let the little grey cells do their work"); - poirotsToDos.add("trim mustache"); - poirotsToDos.add("call all suspects together"); - poirotsToDos.add("reveal the truth of the crime"); - - // Print the size of each ArrayList below: - - - - // Print the name of the detective with the larger to-do list: - - } - + + public static void main(String[] args) { + + // Sherlock + ArrayList sherlocksToDos = new ArrayList(); + + sherlocksToDos.add("visit the crime scene"); + sherlocksToDos.add("play violin"); + sherlocksToDos.add("interview suspects"); + sherlocksToDos.add("solve the case"); + sherlocksToDos.add("apprehend the criminal"); + + // Poirot + ArrayList poirotsToDos = new ArrayList(); + + poirotsToDos.add("visit the crime scene"); + poirotsToDos.add("interview suspects"); + poirotsToDos.add("let the little grey cells do their work"); + poirotsToDos.add("trim mustache"); + poirotsToDos.add("call all suspects together"); + poirotsToDos.add("reveal the truth of the crime"); + + // Print the size of each ArrayList below: + int Sherlock = sherlocksToDos.size(); + int Poirot = poirotsToDos.size(); + System.out.println(Sherlock); + System.out.println(Poirot); + + + // Print the name of the detective with the larger to-do list: + + if(Sherlock > Poirot) { + System.out.println("Sherlock"); + } + else { + System.out.println("Poirot"); + } + + } + } From 050d5804ec3739005916d19e3f12eafefc75b9d2 Mon Sep 17 00:00:00 2001 From: MahsaMv <156520622+MahsaMv@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:18:26 +0330 Subject: [PATCH 3/6] Shuffle.java --- Shuffle => Shuffle.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Shuffle => Shuffle.java (100%) diff --git a/Shuffle b/Shuffle.java similarity index 100% rename from Shuffle rename to Shuffle.java From 8732fb3a3ffdb25a7b3afbeaa514ac573de01a11 Mon Sep 17 00:00:00 2001 From: MahsaMv <156520622+MahsaMv@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:21:12 +0330 Subject: [PATCH 4/6] Update HashCollisionChecker.java --- HashCollisionChecker.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/HashCollisionChecker.java b/HashCollisionChecker.java index 80631a7..4edc570 100644 --- a/HashCollisionChecker.java +++ b/HashCollisionChecker.java @@ -2,14 +2,20 @@ public class HashCollisionChecker { public static int countOfUniqueHashCodes(HashSet set) { - // TODO: Implement - return 0; + HashSet uniqueHashCodes = new HashSet<>(); + for (T item : set) { + uniqueHashCodes.add(item.hashCode()); + } + return uniqueHashCodes.size(); } - public static int countOfUniqueHashCodes(HashMap map) { - // TODO: Implement - return 0; + HashSet uniqueHashCodes = new HashSet<>(); + for (K key : map.keySet()) { + uniqueHashCodes.add(key.hashCode()); + } + return uniqueHashCodes.size(); } +} public static void main(String[] args) { HashSet set = new HashSet<>(); @@ -18,12 +24,12 @@ public static void main(String[] args) { set.add("c#c#c#c#c#c#bBc#c#c#c#c#aa"); set.add("1234"); set.add("c#c#c#c#c#c#bBc#c#c#c#c#bB"); - System.out.println(countOfUniqueHashCodes(set)); // 3 + System.out.println(HashCollisionChecker.countOfUniqueHashCodes(set)); // 3 HashMap map = new HashMap<>(); map.put("c#c#c#c#c#c#c#aaaaaaaabBbB", 14); map.put("c#c#c#c#c#c#c#aaaaaaaac#c#", 12); map.put("c#c#c#c#c#c#c#aaaaaaaac#cc", 16); - System.out.println(countOfUniqueHashCodes(map)); // 2 + System.out.println(HashCollisionChecker.countOfUniqueHashCodes(map)); // 2 } } From d5e76cb241e1e5e61d511834f85c99e60512cc5e Mon Sep 17 00:00:00 2001 From: MahsaMv <156520622+MahsaMv@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:27:03 +0330 Subject: [PATCH 5/6] Cars.java --- Cars.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Cars.java diff --git a/Cars.java b/Cars.java new file mode 100644 index 0000000..2b63bb0 --- /dev/null +++ b/Cars.java @@ -0,0 +1,22 @@ +import java.util.*; +public class Main { + public static void main(String[] args) { + Queue Cars = new LinkedList<>(); + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + for (int i = 0; i < n; i++){ + Cars.add(sc.next()); + } + + for (int i = 0; i < n; i++){ + System.out.println(Cars.poll()); + } + + if (Cars.isEmpty()) { + System.out.println("is empty"); + } + else { + System.out.println("is not empty"); + } + } +} From fb3a309c45dec1a268705c1b81ebd4388dacacd7 Mon Sep 17 00:00:00 2001 From: MahsaMv <156520622+MahsaMv@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:28:57 +0330 Subject: [PATCH 6/6] University.java --- University.java | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 University.java diff --git a/University.java b/University.java new file mode 100644 index 0000000..d799697 --- /dev/null +++ b/University.java @@ -0,0 +1,73 @@ +public class Student implements Comparable { + private String Name; + private int ID; + private Double GPA; + public Student (String Name, int ID, Double GPA){ + this.Name = Name; + this.ID = ID; + this.GPA = GPA; + } + public String getName() { + return Name; + } + public void setName(String Name){ + this.Name = Name; + } + public int getID() { + return ID; + } + public void setID(int ID) { + this.ID = ID; + } + public Double getGPA() { + return GPA; + } + public void setGPA(Double GPA) { + this.GPA = GPA; + } + + public int compareTo(Student other) { + return Integer.compare(this.ID, other.ID); + } + public String toString() { + return "Name: " + Name + ", Student ID: " + ID + ", GPA: " + GPA; + } +} + +import java.util.Scanner; +import java.util.TreeSet; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + TreeSet students = new TreeSet<>(); + + System.out.println("Enter number of students:"); + int numberOfStudents = sc.nextInt(); + sc.nextLine(); + for (int i = 0; i < numberOfStudents; i++) { + System.out.println("Student " + (i + 1) + ":"); + System.out.print("Name: "); + String Name = sc.nextLine(); + System.out.print("Student ID: "); + int ID = sc.nextInt(); + System.out.print("GPA: "); + double GPA = sc.nextDouble(); + sc.nextLine(); + + students.add(new Student(Name, ID, GPA)); + } + + System.out.print("Enter student ID to search: "); + int searchID = sc.nextInt(); + Student searchStudent = new Student("", searchID, 0.0); + + Student result = students.ceiling(searchStudent); + + if (result != null && result.getID() == searchID) { + System.out.println("Student found: " + result); + } else { + System.out.println("Student not found."); + } + } +}