Question: This Exercise uses the String methods indexOf(), subString(), and replace(). It also uses an ArrayList as a container for the web links in a web

This Exercise uses the String methods indexOf(), subString(), and replace(). It also uses an ArrayList as a container for the web links in a web page. This Exercise builds on the LinkList Exercise except instead of printing the Link out to the console in the hrefSearch method; .add the link to an ArrayList after the surrounding hyphens have been removed. The main method has already been completed. Change the hrefSearch method to: 1. Remove the quotes from the string with the String .replace() method 2. Add the links to the ArrayList "linkList" When passing arguments to a method, primitive data types are passed by value. Objects are passed by reference. This means that an ArrayList declared in the main method can have values added to it in called methods by passing the reference to the ArrayList to the called method. Page 288 and 289 in the book explain this principle. The additional "for" loop in the Main Method prints out the links Output should look similar to: http://www.google.com http://web.nmsu.edu/~pbraker/ http://www.dogpile.com http://www.yahoo.com http://learn.nmsu.edu

What I have so far:

import java.io.IOException; import java.net.*; import java.util.*;

/** * Date Created * @author Student Name * FileName: WebCrawler.java */ public class WebCrawler {

/** * @param args the command line arguments */ public static void main(String[] args) throws MalformedURLException, IOException { ArrayList linkList = new ArrayList(); String htmlCode = ""; // This code will grab a webpage and store it in a string object. htmlCode = new Scanner(new URL("http://web.nmsu.edu/~pbraker").openStream(), "UTF-8").useDelimiter("\\A").next();

int linkStart = 0; int endLink = 0; while (true) { linkStart = hrefSearch(linkList, htmlCode); if (linkStart == -1) { break; } htmlCode = htmlCode.substring(linkStart);

} // end while

for (String link : linkList) { System.out.println(link); } } // end Main method

public static int hrefSearch(ArrayList linkList, String inStr) { //***** enter the method code here *********

}// end hrefSearch method } // end WebCrawler

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!