From 52a7e59e920e8f8c2c5e5f7b42fe670f919b1699 Mon Sep 17 00:00:00 2001 From: Malenia <82274616+TheMalenia@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:25:37 -0700 Subject: [PATCH 1/7] Update Detective.java --- Detective.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Detective.java b/Detective.java index 5707416..40ccc3c 100644 --- a/Detective.java +++ b/Detective.java @@ -25,10 +25,18 @@ public static void main(String[] args) { poirotsToDos.add("reveal the truth of the crime"); // Print the size of each ArrayList below: - + System.out.println("Sherlock: " + sherlocksToDos.size()); + System.out.println("Poirot: " + poirotsToDos.size()); // Print the name of the detective with the larger to-do list: + if (sherlocksToDos.size() > poirotsToDos.size()) { + System.out.println("Sherlock."); + } else if (sherlocksToDos.size() < poirotsToDos.size()) { + System.out.println("Poirot."); + } else { + System.out.println("Equal."); + } } From c4a73672f7b4f9bcaaa0a76ce264d52d67415118 Mon Sep 17 00:00:00 2001 From: Malenia <82274616+TheMalenia@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:31:33 -0700 Subject: [PATCH 2/7] Update HashCollisionChecker.java --- HashCollisionChecker.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/HashCollisionChecker.java b/HashCollisionChecker.java index 80631a7..6a73e86 100644 --- a/HashCollisionChecker.java +++ b/HashCollisionChecker.java @@ -1,14 +1,20 @@ import java.util.*; -public class HashCollisionChecker { +class HashCollisionChecker { public static int countOfUniqueHashCodes(HashSet set) { - // TODO: Implement - return 0; + HashSet hashCodes = new HashSet<>(); + for (T item : set) { + hashCodes.add(item.hashCode()); + } + return hashCodes.size(); } public static int countOfUniqueHashCodes(HashMap map) { - // TODO: Implement - return 0; + HashSet hashCodes = new HashSet<>(); + for (K key : map.keySet()) { + hashCodes.add(key.hashCode()); + } + return hashCodes.size(); } public static void main(String[] args) { From 85b96743aecfa623c7a00286fca6a919d41e4106 Mon Sep 17 00:00:00 2001 From: Malenia <82274616+TheMalenia@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:23:05 -0700 Subject: [PATCH 3/7] Update and rename Detective.java to ToDos.java --- Detective.java => ToDos.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Detective.java => ToDos.java (98%) diff --git a/Detective.java b/ToDos.java similarity index 98% rename from Detective.java rename to ToDos.java index 40ccc3c..3757e3d 100644 --- a/Detective.java +++ b/ToDos.java @@ -1,7 +1,7 @@ import java.util.ArrayList; -class ToDos { +public class ToDos { public static void main(String[] args) { From 89bfe0f682fe79fdb523d00d44a351e3e92e413e Mon Sep 17 00:00:00 2001 From: Malenia <82274616+TheMalenia@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:23:27 -0700 Subject: [PATCH 4/7] Update HashCollisionChecker.java --- HashCollisionChecker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HashCollisionChecker.java b/HashCollisionChecker.java index 6a73e86..783ae2f 100644 --- a/HashCollisionChecker.java +++ b/HashCollisionChecker.java @@ -1,6 +1,6 @@ import java.util.*; -class HashCollisionChecker { +public class HashCollisionChecker { public static int countOfUniqueHashCodes(HashSet set) { HashSet hashCodes = new HashSet<>(); for (T item : set) { From c1394f35558311c72ee806c34765219ca4a05a0d Mon Sep 17 00:00:00 2001 From: Malenia <82274616+TheMalenia@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:25:06 -0700 Subject: [PATCH 5/7] Create University.java --- University.java | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 University.java diff --git a/University.java b/University.java new file mode 100644 index 0000000..221efdd --- /dev/null +++ b/University.java @@ -0,0 +1,61 @@ +import java.util.TreeSet; + +class Student implements Comparable { + private int id; + private String name; + private double moadel; + + public Student(int id, String name, double moadel) { + this.id = id; + this.name = name; + this.moadel = moadel; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public double getMoadel() { + return moadel; + } + + @Override + public int compareTo(Student other) { + return Integer.compare(this.id, other.id); + } +} + +public class University { + private TreeSet students; + + public University() { + students = new TreeSet<>(); + } + + public void addStudent(int id, String name, double moadel) { + students.add(new Student(id, name, moadel)); + } + + public String searchStudentById(int id) { + for (Student student : students) { + if (student.getId() == id) { + return "Name: " + student.getName() + ", Moadel: " + student.getMoadel(); + } + } + return "Student not found."; + } + + public static void main(String[] args) { + University university = new University(); + university.addStudent(1, "Hasan", 3.5); + university.addStudent(2, "Shima", 3.8); + university.addStudent(3, "Amir", 3.9); + + System.out.println(university.searchStudentById(2)); + System.out.println(university.searchStudentById(4)); + } +} From 5ea0497cd3b465ddcfd9a440c7934f405d63b2bd Mon Sep 17 00:00:00 2001 From: Malenia <82274616+TheMalenia@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:28:31 -0700 Subject: [PATCH 6/7] Create ShuffleLinkedList.java --- ShuffleLinkedList.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 ShuffleLinkedList.java diff --git a/ShuffleLinkedList.java b/ShuffleLinkedList.java new file mode 100644 index 0000000..176ac7b --- /dev/null +++ b/ShuffleLinkedList.java @@ -0,0 +1,17 @@ +import java.util.Collections; +import java.util.LinkedList; + +public class ShuffleLinkedList { + public static void main(String[] args) { + LinkedList list = new LinkedList<>(); + list.add(45); + list.add("GFG"); + list.add(2.56f); + list.add(3.14); + list.add("Ali"); + list.add(true); + System.out.println("Before: " + list.toString()); + Collections.shuffle(list); + System.out.println("After: " + list.toString()); + } +} From 7dc38e1cbd3f97ce00897ef2267673add03acf19 Mon Sep 17 00:00:00 2001 From: Malenia <82274616+TheMalenia@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:34:48 -0700 Subject: [PATCH 7/7] Create CarQueue.java --- CarQueue.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 CarQueue.java diff --git a/CarQueue.java b/CarQueue.java new file mode 100644 index 0000000..3510ca8 --- /dev/null +++ b/CarQueue.java @@ -0,0 +1,26 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class CarQueue { + public static void main(String[] args) { + Queue carQueue = new LinkedList<>(); + + carQueue.add("BMW"); + carQueue.add("Toyota"); + carQueue.add("Honda"); + + System.out.println("Queue: " + carQueue); + String firstCar = carQueue.poll(); + System.out.println("Queue: " + carQueue); + String secondCar = carQueue.poll(); + System.out.println("Queue: " + carQueue); + String thirdCar = carQueue.poll(); + System.out.println("Queue: " + carQueue); + + if (carQueue.isEmpty()) { + System.out.println("Empty."); + } else { + System.out.println("Not Empty."); + } + } +}