Skip to content

joshj97/Assignment3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Assignment3

Assignment 3 for Data Structures

cisc3130

Instructor: Katherine Chuang
Brooklyn College Kujtim Hakaj

Objective:

To build a program that is able to count each word in a .txt file and bring back the amount of times each word appears in order.

Solution:

What I did was create two seperate methods, one that counts the words line by line using a hashmap to keep track, and one that transfers the keys of the hashmaps into an array to ensure they're printed in order. I did this by using insertion sorting. Without doing this, the hashmap would print out the words in a randomized order.

To ensure the most efficient code is working, it is best to first remove the obstructions (!,?," ", etc.) first and implement each word from this line into an array, which is then read by a for loop that implements it into the hashmap. Once this is done the .keySet() method could be used to transfer it back into an array to make sure we can print out the results in size order.

Example: file.txt

'pop. pop! DROP drOp,'

output:

    2: pop
    2: drop

I made sure to take care of anything that could potentially get in the way of counting the words, like punctuation or capitalization.

About

Assignment 3 for Data Structures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%