SlideShare a Scribd company logo
1 of 1
Download to read offline
*** My code below is working fine but I just need help with the Unique words part. I tried to do
it, but it just keeps iterating over and over. I just want it to be printed once. Keep in mind that
when you're adding, each unique word gets it own entry as a key. Please help me. DO NOT USE
HASHSET OR DON'T IMPORT ANYTHING!!!. Thank you in advance for your help****
Output is supposed to look like this: import java.io.File; import
java.io.FileNotFoundException; import java.util.Iterator; import java.util.Scanner; public class
WordFrequency { public static void main(String[] args) { HashedDictionary collision =
new HashedDictionary<>(); int[] tableLengths = {1361, 1637, 2011}; // Hash table lengths
to be tested System.out.println("Word Frequency by C.Murillon");
System.out.println("Count Word"); System.out.println("----- ----------------------");
for (int i = 0; i < tableLengths.length; i++) { HashedDictionary dictionary = new
HashedDictionary<>(tableLengths[i]); try { Scanner scanner = new
Scanner(new File("usconstitution.txt")); //FIX NAME OF THE FILE while
(scanner.hasNext()) { String word = scanner.next().toLowerCase(); // convert word
to lowercase before hashing if (dictionary.contains(word)) {
dictionary.add(word, dictionary.getValue(word) + 1); } else {
dictionary.add(word, 1); } } scanner.close(); } catch
(FileNotFoundException e) { e.printStackTrace(); } Iterator keyIterator
= dictionary.getKeyIterator(); while (keyIterator.hasNext()) { String word =
keyIterator.next(); System.out.printf("%-8d%-24sn", dictionary.getValue(word),
word); } collision.add(Integer.toString(tableLengths[i]),
dictionary.getCollisionCount()); System.out.println("Unique words = "
+dictionary.getSize()); } // Output the combined results for all hash table lengths
System.out.println("TablenLength Collision"); for (int i = 0; i < tableLengths.length; i++) {
System.out.printf("%-7d%dn", tableLengths[i],
collision.getValue(Integer.toString(tableLengths[i]))); } } }

More Related Content

More from americanopticalscbe

Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdf
 Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdf Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdf
Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdfamericanopticalscbe
 
myList is an object of type ListFromOneString. myList currently con.pdf
 myList is an object of type ListFromOneString. myList currently con.pdf myList is an object of type ListFromOneString. myList currently con.pdf
myList is an object of type ListFromOneString. myList currently con.pdfamericanopticalscbe
 
Name Draw the front on the following sarface imap, using rgproprixte.pdf
 Name Draw the front on the following sarface imap, using rgproprixte.pdf Name Draw the front on the following sarface imap, using rgproprixte.pdf
Name Draw the front on the following sarface imap, using rgproprixte.pdfamericanopticalscbe
 
My private pilot training took place in 1977 in a Cessna 150 from Rya.pdf
 My private pilot training took place in 1977 in a Cessna 150 from Rya.pdf My private pilot training took place in 1977 in a Cessna 150 from Rya.pdf
My private pilot training took place in 1977 in a Cessna 150 from Rya.pdfamericanopticalscbe
 
Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdf
 Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdf Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdf
Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdfamericanopticalscbe
 
Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdf
 Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdf Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdf
Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdfamericanopticalscbe
 
Mycocepurus ant and social parasite Figure. A queen of the social par.pdf
 Mycocepurus ant and social parasite Figure. A queen of the social par.pdf Mycocepurus ant and social parasite Figure. A queen of the social par.pdf
Mycocepurus ant and social parasite Figure. A queen of the social par.pdfamericanopticalscbe
 
Multiple choice Select the correct answer from the list provided. 17.pdf
 Multiple choice Select the correct answer from the list provided. 17.pdf Multiple choice Select the correct answer from the list provided. 17.pdf
Multiple choice Select the correct answer from the list provided. 17.pdfamericanopticalscbe
 
Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdf
 Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdf Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdf
Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdfamericanopticalscbe
 
M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdf
 M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdf M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdf
M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdfamericanopticalscbe
 
Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdf
 Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdf Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdf
Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdfamericanopticalscbe
 
Muliple Chaice a pice hugw than 56 a nice .pdf
 Muliple Chaice a pice hugw than 56 a nice .pdf Muliple Chaice a pice hugw than 56 a nice .pdf
Muliple Chaice a pice hugw than 56 a nice .pdfamericanopticalscbe
 
Comprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdf
Comprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdfComprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdf
Comprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdfamericanopticalscbe
 
Comprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdf
Comprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdfComprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdf
Comprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdfamericanopticalscbe
 
Comportamiento organizacional 2-1 Describa las dos formas princip.pdf
Comportamiento organizacional 2-1 Describa las dos formas princip.pdfComportamiento organizacional 2-1 Describa las dos formas princip.pdf
Comportamiento organizacional 2-1 Describa las dos formas princip.pdfamericanopticalscbe
 
Compare DNA sequence between species to build a phylogeny. There are.pdf
Compare DNA sequence between species to build a phylogeny. There are.pdfCompare DNA sequence between species to build a phylogeny. There are.pdf
Compare DNA sequence between species to build a phylogeny. There are.pdfamericanopticalscbe
 
Compare lists and tuples. Which one is not rightLists can be edi.pdf
Compare lists and tuples. Which one is not rightLists can be edi.pdfCompare lists and tuples. Which one is not rightLists can be edi.pdf
Compare lists and tuples. Which one is not rightLists can be edi.pdfamericanopticalscbe
 
Consider the following data for a closed economyY =$13trillio.pdf
Consider the following data for a closed economyY =$13trillio.pdfConsider the following data for a closed economyY =$13trillio.pdf
Consider the following data for a closed economyY =$13trillio.pdfamericanopticalscbe
 
Consider the following (AI-generated) response to the question Why .pdf
Consider the following (AI-generated) response to the question Why .pdfConsider the following (AI-generated) response to the question Why .pdf
Consider the following (AI-generated) response to the question Why .pdfamericanopticalscbe
 
Consider the difference between cultural relativism (where right and.pdf
Consider the difference between cultural relativism (where right and.pdfConsider the difference between cultural relativism (where right and.pdf
Consider the difference between cultural relativism (where right and.pdfamericanopticalscbe
 

More from americanopticalscbe (20)

Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdf
 Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdf Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdf
Nanial ano 28 ic cinclo and hac the followinn inromo and ovnoncoc in .pdf
 
myList is an object of type ListFromOneString. myList currently con.pdf
 myList is an object of type ListFromOneString. myList currently con.pdf myList is an object of type ListFromOneString. myList currently con.pdf
myList is an object of type ListFromOneString. myList currently con.pdf
 
Name Draw the front on the following sarface imap, using rgproprixte.pdf
 Name Draw the front on the following sarface imap, using rgproprixte.pdf Name Draw the front on the following sarface imap, using rgproprixte.pdf
Name Draw the front on the following sarface imap, using rgproprixte.pdf
 
My private pilot training took place in 1977 in a Cessna 150 from Rya.pdf
 My private pilot training took place in 1977 in a Cessna 150 from Rya.pdf My private pilot training took place in 1977 in a Cessna 150 from Rya.pdf
My private pilot training took place in 1977 in a Cessna 150 from Rya.pdf
 
Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdf
 Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdf Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdf
Multiple-Step Income Statement On March 31,20Y4, the balances of the .pdf
 
Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdf
 Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdf Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdf
Multiple Choice decrease AD2 to AD1 Increase AS1 to AS2 Increase A.pdf
 
Mycocepurus ant and social parasite Figure. A queen of the social par.pdf
 Mycocepurus ant and social parasite Figure. A queen of the social par.pdf Mycocepurus ant and social parasite Figure. A queen of the social par.pdf
Mycocepurus ant and social parasite Figure. A queen of the social par.pdf
 
Multiple choice Select the correct answer from the list provided. 17.pdf
 Multiple choice Select the correct answer from the list provided. 17.pdf Multiple choice Select the correct answer from the list provided. 17.pdf
Multiple choice Select the correct answer from the list provided. 17.pdf
 
Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdf
 Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdf Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdf
Nash Inc s EPS is $7.27 and its dividend payout ratio is 0.7 . If th.pdf
 
M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdf
 M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdf M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdf
M�tiple Chaice Porffolio investment moitly represents the sole and pu.pdf
 
Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdf
 Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdf Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdf
Naren is dating a girl named Felicity. Naren and Felicity both cautio.pdf
 
Muliple Chaice a pice hugw than 56 a nice .pdf
 Muliple Chaice a pice hugw than 56 a nice .pdf Muliple Chaice a pice hugw than 56 a nice .pdf
Muliple Chaice a pice hugw than 56 a nice .pdf
 
Comprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdf
Comprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdfComprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdf
Comprehensive Illustration (Estimated Time 60 to 75 Minutes) On Jan.pdf
 
Comprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdf
Comprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdfComprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdf
Comprehensive Problem 1 - Part 1 Taxpayer information,2022 Form 104.pdf
 
Comportamiento organizacional 2-1 Describa las dos formas princip.pdf
Comportamiento organizacional 2-1 Describa las dos formas princip.pdfComportamiento organizacional 2-1 Describa las dos formas princip.pdf
Comportamiento organizacional 2-1 Describa las dos formas princip.pdf
 
Compare DNA sequence between species to build a phylogeny. There are.pdf
Compare DNA sequence between species to build a phylogeny. There are.pdfCompare DNA sequence between species to build a phylogeny. There are.pdf
Compare DNA sequence between species to build a phylogeny. There are.pdf
 
Compare lists and tuples. Which one is not rightLists can be edi.pdf
Compare lists and tuples. Which one is not rightLists can be edi.pdfCompare lists and tuples. Which one is not rightLists can be edi.pdf
Compare lists and tuples. Which one is not rightLists can be edi.pdf
 
Consider the following data for a closed economyY =$13trillio.pdf
Consider the following data for a closed economyY =$13trillio.pdfConsider the following data for a closed economyY =$13trillio.pdf
Consider the following data for a closed economyY =$13trillio.pdf
 
Consider the following (AI-generated) response to the question Why .pdf
Consider the following (AI-generated) response to the question Why .pdfConsider the following (AI-generated) response to the question Why .pdf
Consider the following (AI-generated) response to the question Why .pdf
 
Consider the difference between cultural relativism (where right and.pdf
Consider the difference between cultural relativism (where right and.pdfConsider the difference between cultural relativism (where right and.pdf
Consider the difference between cultural relativism (where right and.pdf
 

Recently uploaded

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

My code below is working fine but I just need help with the Unique.pdf

  • 1. *** My code below is working fine but I just need help with the Unique words part. I tried to do it, but it just keeps iterating over and over. I just want it to be printed once. Keep in mind that when you're adding, each unique word gets it own entry as a key. Please help me. DO NOT USE HASHSET OR DON'T IMPORT ANYTHING!!!. Thank you in advance for your help**** Output is supposed to look like this: import java.io.File; import java.io.FileNotFoundException; import java.util.Iterator; import java.util.Scanner; public class WordFrequency { public static void main(String[] args) { HashedDictionary collision = new HashedDictionary<>(); int[] tableLengths = {1361, 1637, 2011}; // Hash table lengths to be tested System.out.println("Word Frequency by C.Murillon"); System.out.println("Count Word"); System.out.println("----- ----------------------"); for (int i = 0; i < tableLengths.length; i++) { HashedDictionary dictionary = new HashedDictionary<>(tableLengths[i]); try { Scanner scanner = new Scanner(new File("usconstitution.txt")); //FIX NAME OF THE FILE while (scanner.hasNext()) { String word = scanner.next().toLowerCase(); // convert word to lowercase before hashing if (dictionary.contains(word)) { dictionary.add(word, dictionary.getValue(word) + 1); } else { dictionary.add(word, 1); } } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } Iterator keyIterator = dictionary.getKeyIterator(); while (keyIterator.hasNext()) { String word = keyIterator.next(); System.out.printf("%-8d%-24sn", dictionary.getValue(word), word); } collision.add(Integer.toString(tableLengths[i]), dictionary.getCollisionCount()); System.out.println("Unique words = " +dictionary.getSize()); } // Output the combined results for all hash table lengths System.out.println("TablenLength Collision"); for (int i = 0; i < tableLengths.length; i++) { System.out.printf("%-7d%dn", tableLengths[i], collision.getValue(Integer.toString(tableLengths[i]))); } } }