diff --git a/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMap.java b/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMap.java index 10720aa..8c7f05a 100644 --- a/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMap.java +++ b/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMap.java @@ -1,5 +1,7 @@ - + /** + * Write a description of class MostFrequentWordHashMap. + * * 1. Generate an Hashmap of string and integers * 2. Generate an input of strings * 1.for items in the input @@ -7,6 +9,9 @@ * b.add it and increment the value * c. else * d. increment the value + * + * @author (Aymar S. NAHUM) + * @version (10/20/2024) * */ import java.util.HashMap; @@ -30,24 +35,28 @@ public MostFrequentWordHashMap() /** * An example of a method - replace this comment with your own - * * @param y a sample parameter for a method * @return the sum of x and y */ - public static HashMap mapUniqueMethod(ArrayList input) - { + // The dynamic compiler often increments the outcome + // A solution is to generate a clear function + // uniqueMap.clear() + public static void clearMap(ArrayList input){ - //uniqueMap.clear(); - //The compiler is dynamic and increments the outcome at each iteration - //A workaround can be to loop the clear function - - for(int i = 0 ; i < input.size() ; i = i + 1) - { - uniqueMap.clear(); + + for(int i = 0 ; i < input.size(); i = i + 1){ + uniqueMap.put( null, null); } + + } + + public static HashMap mapUniqueMethod(ArrayList input) + { - + //To avoid dynamic issues, clear the hashMap first. + //Can't reproduce + uniqueMap.remove(uniqueMap.get(null)); for(int i = 0 ; i < input.size() ; i = i + 1) { if(!uniqueMap.containsKey(input.get(i))){ diff --git a/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMapTest.java b/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMapTest.java index cdb5fa7..28b3806 100644 --- a/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMapTest.java +++ b/Week2/Most frequent Word/MostFrequentWordHashMap/MostFrequentWordHashMapTest.java @@ -1,14 +1,15 @@ /** - * Write a description of class testUniqueWordMap here. + * Write a description of class MostFrequentWordHashMapTest. * - * @author (your name) - * @version (a version number or a date) + * @author (Aymar S. NAHUM) + * @version (10/20/2024) */ import java.util.ArrayList; -public class MostFrequentWordHashMapTest -{ +public class MostFrequentWordHashMapTest{ + + // instance variables - replace the example below with your own public static ArrayList in = new ArrayList(); @@ -46,6 +47,7 @@ public static void testUniqueHashMethod() MostFrequentWordHashMap MostFrequentWordHashMap = new MostFrequentWordHashMap(); //MostFrequentWordHashMap.mapUniqueMethod(in); + MostFrequentWordHashMap.clearMap(in); MostFrequentWordHashMap.findMaxMethod(MostFrequentWordHashMap.mapUniqueMethod(in)); } }