| | |
Word Frequency Count
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I'm supposed to be inserting words from a text file into a BST and AVL tree. I've got the words to insert correctly, and it recognizes whenever the words are repeated. It just leaves the count at 2 instead of incrementing afterwards. Can't seem to figure out why it's not taking the count at the moment it finds a repeat.
The variable
Any help would be much appreciated
Java Syntax (Toggle Plain Text)
try { FileReader reader = new FileReader("mlkdream1.txt"); Scanner in = new Scanner(reader); while (in.hasNext()) { tmp = in.next(); tmp = tmp.toUpperCase(); word = new WordStat(tmp, 1); if(!Bst1.inTree(word)) { Bst1.insert(word); Avl1.insert(word); count++; } else { Avl1.retrieve(word); word.updateCount(1); Bst1.insert(word); Avl1.insert(word); } } reader.close();
The variable
word is of the type WordStat, which is defined as (String word, int frequency). The updateCount(Integer) method is supposed to grab the original count, and increment it by the number passed to it. I don't think the retrieve is wrong, because that was already written for us. Any help would be much appreciated
Well when I compare two Strings in java I use this, could that possibly be the problem?
Whereas I can't explicitly write:
Java Syntax (Toggle Plain Text)
String one = "iamthwee"; String two = "nonsense"; if (one.equals(two)) { System.out.println("Both strings are the same"); }
Whereas I can't explicitly write:
Java Syntax (Toggle Plain Text)
if (one == two) { System.out.println("Both strings are the same"); }
Well, I was able to find out what was wrong. I was trying to do...
I had a problem in my declarations. It would give me a comparable error everytime. I had forgotten to call Bstree<WordStat>, so that's where I messed up. It compared them correctly, that's what the
Java Syntax (Toggle Plain Text)
WordStat update; update = Avl1.retrieve(word)
I had a problem in my declarations. It would give me a comparable error everytime. I had forgotten to call Bstree<WordStat>, so that's where I messed up. It compared them correctly, that's what the
inTree() function did for me. Anyways, seems there was no point to this post :rolleyes: Thanks for trying to help though. ![]() |
Similar Threads
- need help on my code about word frequency counter (C++)
- Word Frequency Counter Help (Java)
- Word Count in Scheme (Computer Science)
- Word and Letter Count (C)
Other Threads in the Java Forum
- Previous Thread: deprecation in ActionError in struts
- Next Thread: java illiterate
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop map method methods mobile netbeans newbie objects online oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu update windows






