From 573ed631a3ea7be7358a60d052f9e449b2403547 Mon Sep 17 00:00:00 2001 From: mobina sakhavat Date: Sat, 29 Jun 2024 23:52:56 +0330 Subject: [PATCH] has done --- Detective.java | 26 +++++++++++++++----------- HashCollisionChecker.java | 14 ++++++++++---- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Detective.java b/Detective.java index 5707416..a3772bb 100644 --- a/Detective.java +++ b/Detective.java @@ -1,35 +1,39 @@ - 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: + System.out.println("Sherlock's to-do list size: " + sherlocksToDos.size()); + System.out.println("Poirot's to-do list size: " + poirotsToDos.size()); - - // Print the name of the detective with the larger to-do list: - + if (sherlocksToDos.size() > poirotsToDos.size()) { + System.out.println("Sherlock has more tasks."); + } else if (sherlocksToDos.size() < poirotsToDos.size()) { + System.out.println("Poirot has more tasks."); + } else { + System.out.println("Both detectives have the same number of tasks."); + } } - } diff --git a/HashCollisionChecker.java b/HashCollisionChecker.java index 80631a7..9a7ffb3 100644 --- a/HashCollisionChecker.java +++ b/HashCollisionChecker.java @@ -2,13 +2,19 @@ public 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) {