CS 10, Fall 2008
Assignment 5

Due: Wednesday, December 3, 9:00pm
Worth: 100 homework points

  1. Twice implement interface TextGetter - once for a text file and once for a web page. Both class declarations must include the clause, implements TextGetter. Provide javadoc comments where appropriate. Use TextTester.java to test your classes.
    Note - copies of all necessary files for this assignment are also in ~mikec/cs10/hw5/ on CSIL.
    1. Write FileText.java to read text from a text file (like short.txt or longer.txt).
      • Include a constructor that takes as its only argument the file name as a String.
      • This class does not have to catch IOExceptions, but it does have to close any file that it opens. See "The finally Clause" - text section 11.5.
      • The getText() method should return the entire contents of the file as a String, including all newline and other special characters.
      • Execute the test program as follows to test this class:
        java TextTester filename
        where filename is the name of the file to read. For example,
        java TextTester short.txt
        should produce the results shown in the second of these sample TextTester runs (done at CSIL).
    2. Write WebText.java to read text from a web page.
      • See the text's Programming Project 11.1 (p. 526) for guidance.
      • Include a constructor that takes one String argument, a properly formatted URL string.
      • The class does not have to catch IOExceptions of any kind.
      • The getText() method should return the entire contents of the web page as a String.
      • Execute the test program as follows to test this class:
        java TextTester -u address
        where address is a properly formatted web address (URL) to read. For example,
        java TextTester -u http://cs.ucsb.edu/~cs10/samplepage.html
        should produce results that match the third of the sample TextTester runs.
  2. Now implement interface Cipher - to encrypt/decrypt text. Your class declaration must include the clause, implements Cipher. Include javadoc comments where appropriate. Use CipherTester.java to test your class.
  3. Write Crypt.java to combine the features of both test programs from parts 1 and 2 into an application that will encrypt/decrypt text either from files or web pages. Match these sample Crypt results from our solution, including the ways in which error cases are handled. Let command line arguments appear in any order, and notice that both the -k option and a single source file (or web page if -u option) are mandatory arguments.
  4. Turn in four required files from your engineering account as follows:
    turnin hw5@cs10 FileText.java WebText.java VigCipher.java Crypt.java
    Late assignments may not be accepted.

Updated November 19, 2008, by C. Michael Costanzo.