Lab Assignment 4
CS202, Summer 2004
1.(10pt) Create a new directory D:\Data\FileTest, and under
this directory, create a few more files and sub-directories for
testing. In particular, you need to create at least two
sub-directories, 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:
- Find the number of sub-directories under D:\Data\FileTest
- Find the number of files under D:\Data\FileTest
- Find whether there is a sub-directory called Trash under D:\Data\FileTest,
and if not, create the sub-directory.
- Prompt the user whether to move all .txt files to the trash bin,
and if the user answers yes, move all .txt files under D:\Data\FileTest
to D:\Data\FileTest\Trash.
2.(10pt) 11.23 (b). And a few things about this problem:
- First of all, read the text from a file, and use command line
parameter to provide the file name to your program.
- Secondly, word count is actually not a good measure for analysis,
for example, comparing the number of 3-letter words in a long novel to
the number of 3-letter words in a short novel does not make sense, even
if the two novels are written by the same author. So instead, use the frequencies
of the words. In particular, 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.
- Thirdly, use a "catch-all" counter to count the words with 20 or
more letters.
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 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.(5pt) [Lab Manual] Chapter 15. Lab Exercise 1 (p445-449,
including Follow-up Question and Activity).
4.(5pt) [Lab Manual] Chapter 15. Lab Exercise 2 (p451-452)