Results 1 to 3 of 3
- 07-23-2009, 07:10 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 57
- Rep Power
- 0
cannot find symbol error - help required please..
Can anyone help with this please?
WebPageData is a class to hold all the words from a webpage as a set of strings along with the url for the webpage which is stored as a string.
Finder is a class that holds and searches instances of the WebPageData class.
The WebPageData class is complete and working no problem.
In the code below I have come to a full stop with the searchFor(String) method in the Finder class because the getNumOfHits(String) method is reporting an error; cannot find symbol - method getNumOfHits(java.lang.String), and it will no doubt produce the same error for getUrl(). Can someone please point out how I can amend these two methods in the Finder class to reference instances of the WebPageData class so I can kick myself. Both classes currently exist as part of the same project and the Finder class has a 'uses' relationship with the WebPageData class. Many thanks.
Java Code:import java.util.*; /** * A Class to hold all the words from a particular webpage as a set of strings * along with the url for the webpage stored as a string. */ public class WebPageData { private Set<String> wordSet; private String url; public WebPageData(String text, String theUrl) { super(); this.wordSet = getWordsIn(text); this.url = theUrl; } /** * The String argument is split into individual words * and the words are assigned to an array. * The elements of the array are then added to a set. * The method finally returns the set. */ public static Set<String> getWordsIn(String text) { String[] wordArray = text.split(" "); Set<String> words = new HashSet<String>(); for (int count = 0; count < wordArray.length; count++) { words.add(wordArray[count]); } return words; } /** * Returns the set assigned to wordSet. */ public Set<String> getWordSet() { return this.wordSet; } /** * Returns the String assigned to url. */ public String getUrl() { return this.url; } /** * The String argument is converted into a set * by the re-use of the getWordsIn(String) method * and is assigned to a local variable. * The newly created set is then copied to keep * the original set intact, and the intersection of * the copied set and the wordSet instance variable * is created. Finally the size of the intersection * is returned. */ public int getNumOfHits(String searchString) { Set<String> wordsToFind = getWordsIn(searchString); Set<String> intersection = new HashSet<String>(wordSet); intersection.retainAll(wordsToFind); return intersection.size(); } }Java Code:import java.util.*; /** * A Class to hold and search instances of the WebPageData class. */ public class Finder { private Set<WebPageData> scannedSites; public Finder() { super(); scannedSites = new HashSet<WebPageData>(); } /** * Adds the WebPageData argument to the set referenced * by the scannedSites instance variable. */ public void addSite(WebPageData aPage) { this.scannedSites.add(aPage); } /** * pagesFound is declared as an empty instance of the * HashMap class that implements the Map interface. * For each instance of WebPageData in the scannedSites * set, the number of hits the String argument has * with it should be returned. If the number of hits is * greater than zero then the url String and the number of * hits Integer should be added to the pagesFound Map. */ public void searchFor(String aString) { Map<String, Integer> pagesFound = new HashMap<String, Integer>(); for (Object scan : this.scannedSites) { int hits = ???.getNumOfHits(aString); if (hits > 0) { pagesFound.put(???.getUrl(), ???.getNumOfHits()); } } } }
- 07-23-2009, 10:07 PM #2
Java Code:public void searchFor(String aString) { Map<String, Integer> pagesFound = new HashMap<String, Integer>(); ////// Set<WebPageData> scannedSites ////// // According to this member variable declaration each // element of the Set [i]scannedSites[/i] is of type // WebPageData. So that's what you get when you access // the set elements in this [i]for–each[/i] loop. for (WebPageData pageData : this.scannedSites) { int hits = pageData.getNumOfHits(aString); if (hits > 0) { pagesFound.put(pageData.getUrl(), pageData.getNumOfHits(aString)); } } }
- 07-24-2009, 03:03 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 57
- Rep Power
- 0
thank you thats ace.
i also omitted the String argument within the if statement.
here is my completed code which also now includes a display of the number of words found at each url.
have a good one!
Java Code:public void searchFor(String aString) { Map<String, Integer> pagesFound = new HashMap<String, Integer>(); for (WebPageData pageData : this.scannedSites) { int hits = pageData.getNumOfHits(aString); if (hits > 0) { pagesFound.put(pageData.getUrl(), pageData.getNumOfHits(aString)); } System.out.println(pageData.getNumOfHits(aString) + " words(s) matched at " + pageData.getUrl()); } }
Similar Threads
-
[SOLVED] Cannot find symbol error
By dan0 in forum New To JavaReplies: 17Last Post: 03-03-2009, 05:09 PM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
'Cannot find symbol' error
By minihazard10 in forum New To JavaReplies: 6Last Post: 10-10-2008, 04:05 AM -
Error: cannot find symbol
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:39 AM -
Error: cannot find symbol
By cachi in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks