Problem

WebPageReader program:In addition to testing your exception handling prowess, this exercis...

WebPageReader program:

In addition to testing your exception handling prowess, this exercise also tests your ability to use online help and/or reference books. The following program attempts to read in a Web address and print the contents of the Web page at that address.

 In the given program:

For each class that’s used, add an import statement for it, if it’s necessary.

For each method call and constructor call:

If it throws an unchecked exception, ignore it.

If it throws a checked exception:

  Specify the specific exception in a throws clause.

  Within a catch block in main, catch the exception and print the exception’s message using its getMessage method.

Assume that the following code works except for the items mentioned above.

/************************************************************** WebPageReader.java* Dean & Dean** This reads a Web page.*************************************************************/import java.util.Scanner;public class WebPageReader{BufferedReader reader;public WebPageReader(String webAddress){URL url = new URL(webAddress);URLConnection connection = url.openConnection();InputStream in = connection.getInputStream();reader = new BufferedReader(new InputStreamReader(in));} // end constructor//**********************************************************public String readLine(){return reader.readLine();} // end readLine//**********************************************************public static void main(String[] args){Scanner stdIn = new Scanner(System.in);String url, line;System.out.print("Enter a full URL address: ");url = stdIn.nextLine();WebPageReader wpr = new WebPageReader(url);while ((line = wpr.readLine()) != null){System.out.println(line);}} // end main} // end WebPageReader

Be aware that your program might be correct, but it might not be able to access Web pages successfully. To access Web pages, your computer needs to have Internet access capabilities. If your firewall asks if it’s OK for Java to access the Internet, click “yes” and continue. Here are three sample sessions:

First sample session:

Enter a full URL address: htp://www.park.eduunknown protocol: htp

Second sample session:

Enter a full URL address: http:/www.park.eduConnection refused: connect

Third sample session:

Enter a full URL address: http://www.park.eduPark University Home Page. . .

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT