Programming Exercise 2


This exercise will help you practice file and screen I/O, and some string manipulation in Java. Your program will start by reading in two file names from the screen. To do this, put out a prompt for each file name, as in:

  Enter first file name: testfile1.dat
  Enter second file name: testfile2.dat
The actual file names entered in the example above are testfile1.dat and testfile2.dat. Each of these files is a text file. Each line in such a file will contain a single word, with perhaps some whitespace before or after each word. (No line will be completely blank). For example, the contents of testfile1.dat might be:
  blah
    conservation
   madam
and the contents of testfile2.dat might be:
  blah
    conversation
  blah
  radar
What you need to do is identify the following cases, whenever it occurs: Your program will write output to a text file called results.txt. Also, put all the CASE 1 examples together, then all the CASE 2 examples, then all the CASE 3 examples. So, your results.txt file for the above example files should be:
CASE 1:
  "madam" on line 3 in testfile 1 is a palindrome.
  "radar" on line 4 in testfile 2 is a palindrome.
CASE 2:
  "blah" on line 1 in testfile1 is identical to "blah" on line 1 in testfile2
  "blah" on line 1 in testfile1 is identical to "blah" on line 3 in testfile2

There is no code to download for this exercise. You are free to use code in the course notes in any which way you please. Note that you will need to remove whitespace in front of and after words, if present.

Submission: