Hi, I am completely new to Java and I am currently on my second assignment in my Java class.
I am having a bit of trouble getting my code to do what I need it to do. I'm not getting any errors, but when I runt the program I the console just displays the word that is given and doesn't search the webp pages like it is supposed to. I know this is very simple but again I am a complete beginner and anything helps at this point. Here is the code:
public class SearchEngine {
public static void main(String[] args) {
System.out.println("Creating Index and Scraping Pages");
// 1. Create a new Indexer object
Indexer i = new Indexer();
/* 2. Use the addPage method from this class
* to add the following websites to your index
* FSU's Program in Interdisciplinary Computing
* FSU's Program in Interdisciplinary Computing
* FSU's Program in Interdisciplinary Computing
* FSU's Program in Interdisciplinary Computing */
addPage(i, "http://pic.fsu.edu/");
addPage(i, "http://pic.fsu.edu/about.php");
addPage(i, "http://pic.fsu.edu/people.php");
addPage(i, "http://pic.fsu.edu/students.php");
System.out.println("System ready for queries");
/* 3. Open a input dialog using the JOptionPane class
* and ask for a word to search the index.
* Get the word to search for as a result String.
*/
String word = JOptionPane.showInputDialog(null, "Provide a Word to search the index:");
// 4. Search the index for the word requested, get the result.
i.search(word);
/* 5. Output the search result either to the console
* or using a JOptionPane message dialog.
*/
System.out.println(word);
}
/**
* Describe what this method does here.
* @param i
* @param location
*/
public static void addPage(Indexer i, String location) {
// 1. Get the html code from the location provided to this method
String site = WebGet.httpget(location);
// 2. Create a new page object and set its html code to the code you downloaded
Page p = new Page(site);
// 3. Get the array of words from the page object.
p.getWords();
// 4. Add an entry to the indexer, providing the location and the array of words
i.addEntry(location, p.getWords());
}
}
