Question: In this project you will complete a word counting program. Your task is to write a complete implementation for the class Z00000000 which is used
In this project you will complete a word counting program. Your task is to write a complete implementation for the class Z00000000 which is used to count generic Objects. The type X is a key for looking up objects and the type Y is the type of Objects to be entered. In our application, X is used as a String and represents the lower case version of a word (with any final letter s removed). In our application, Y is also used as a String and represents the word as found. The main method which tests your class uses it to construct a Counter object. The Utility run method operates with your Counter object. The method reads a file called text.txt (or a user specified file if this does not exist) and reports a count of words in it. Two words are considered the same if their only difference is capitalization or a final letter s on the end. The report lists all words that appear at least 10 times together with a count for the word and a list of all versions of the word that were found. A typical line of the report might read: end: total count 61, end, END, Ends, ends, End This means that end was found 61 times and appeared in 5 different forms as end, END, Ends, ends and End. You must complete an implementation for the class Z00000000 which is used to count generic Objects. You might like to implement it as a Map adapter so that you don't have to code a Map ADT. Would you prefer to adapt a java HashMap or TreeMap? What type of keys should be used for the map? What type of values do you need to access? (Hint: I do not think that the Map that you store as an instance variable should use type parameters X and Y. Why not?) If either of these keys or values are of a complex type (more than just one String) you should consider implementing a class to store objects of this type). You could place this new class definition inside the code for Z00000000 to comply with the requirement that only changes to this class should be made.
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Set; public class Z00000000, Y> implements Counter { public static void main(String args[]) throws FileNotFoundException { Counter x = new Z00000000(); Utility.run(x); } public String get(X word) { // implement this return ""; } public int getCount(X word) { // implement this return 0; } public Set keySet() { // implement this return null; } public void put(X keyWord, Y word) { // implement this } // declare any required instance variables or helpful auxiliary types and methods here } // ------- cut here. Place your new code above this line and submit only the ------ // ------- code above this line as your homework. Do not make any code changes ---- // ------- below this line. --------- interface Counter, Y> { int getCount(X word); Set keySet(); void put(X keyWord, Y word); String get(X word); } class Utility { public static void run(Counter words) throws FileNotFoundException{ Scanner terminal = new Scanner(System.in); System.out.println("Give the name of a file for analysis:"); String fileName = terminal.next(); Scanner input = new Scanner(new File( "C:\\Documents and Settings\\alex\\Desktop\\" + fileName)); input.useDelimiter("\\W+"); while (input.hasNext()) { String word = input.next(); String keyWord = Utility.dropS(word); words.put(keyWord, word); } for (String word : words.keySet()) if (words.getCount(word) >= 10) System.out.println(word +":\t" + words.get(word)); input.close(); terminal.close(); } static String dropS(String word) { String ans = word.toLowerCase(); if (ans.endsWith("s")) return ans.substring(0, ans.length() - 1); return ans; } } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
