Lab Assignment 6
CS202, Summer 2006

Please upload your source code files using CSNS. Note that file uploading will be disabled automatically after the lab ends, so please turn in your work on time.

1.(10pt) Write two exception classes, AccountDepositException and AccountWithdrawException, and modify the Account class such that

2.(15pt)  [Textbook 29.19(b)]  (Text Analysis) The availability of computers with string-manipulation capabilities has resulted in some rather interesting approaches to analyzing the writings of great authors. Much attention has been focused on whether William Shakespeare ever lived. Some scholars believe there is substantial evidence indicating that Christopher Marlowe actually penned the masterpieces attributed to Shakespeare. Researchers have used computers to find similarities in the writings of these two authors.

In this exercise, we examines one of the methods for analyzing texts with a computer. In particular, write an application that reads from a file and prints a table indicating the frequencies of one-letter words, two-letter words, three-letter words, and so on, appearing in the file. The frequency of n-letter words in a file is the number of n-letter words in the file divided by the total number of words in the file. For example, if the file contains the following text:

To be, or not to be: that is the question:

Then the output should be

	Word Length	Frequency
2 0.6
3 0.2
4 0.1
8 0.1

Note that you should use command line parameters to provide the file name to your program, and when you calculate the lengths of words, the following punctuation marks should be excluded:

, . ! : ; () " ...

Once you have your program ready, try it with file1.txt, file2.txt, file3.txt, and see if you can decided whether they are written by the same author. These files are downloaded from Project Gutenberg, which provides free e-texts of literary works in public domain. To make things a little more interesting, I've replaced the author names in the files with *****.

3.(10pt) Create a new directory D:\Data\FileTest, and under this directory, create a few files and subdirectories for testing. In particular, you need to create at least two subdirectories, at least three files, and one of those three files must have the .txt extension.

Write a Java application which uses the File class to do the following:

4.(+10pt) Implement a method int fileCount(String directory), which takes the name of a directory as parameter, and returns the number of files under this directory (including the files under the subdirectories of this directory). Write a program to test the method properly.

Note that since we do not know the depth of the subdirectories, it is likely that the method has to work recursively