Assignment #8 - File I/O

Due: Monday, July 28

Task

Write a program that translates an English text file into "Pig Latin". The rules we will use for Pig Latin translation are given below.

Filename should be

Program Requirements

  1. The input file and the output file names are to be specified as command line arguments. Format:
        java PigLatin inputfile outputfile
    
    Sample call:
        java PigLatin letter.txt outfile.txt
    
    This call will read in the input file letter.txt, and it will write the Pig Latin translation of this file to outfile.txt.
     
  2. Required error checking and exception handling
  3. Assuming that the error conditions above do not occur, the program should read the input file and write a translation to Pig Latin to the output file, using the rules described below. Translation is done on words. Characters that are not part of words (punctuation, spaces, newlines, etc) should be written to the output file as-is (no change).
  4. You may use any of the Stream classes discussed in lecture, as well as Character, String, StringBuffer, and/or StringTokenizer. You do not necessarily need all these classes, but you may use any of them that you like. For the Stream classes, be sure to import the java.io package.

Pig Latin Translation Rules

  1. A word is a consecutive sequence of letters (a-z, A-Z) or apostrophes. Note that this means hyphenated words are simply treated as two words. Examples: Zebra , doesn't , apple
  2. If a word starts with a vowel, the Pig Latin version is the original word with "way" added to the end
  3. If a word starts with a consonant, or a series of consecutive consonants, the Pig Latin version transfers all consonants up to the first vowel to the end of the word, and adds "ay" to the end.
  4. The letter 'y' should be treated as a consonant if it is the first letter of a word, and treated as a vowel otherwise.
  5. If the original word is capitalized, the new Pig Latin version of the word should be capitalized in the first letter (i.e. the previous capital letter may not be capitalized any more).
Sample word translations:
  are		-->	areway
  each		-->	eachway
  rabbit	-->	abbitray
  yellow	-->	ellowyay
  bygone	-->	ygonebay
  stretch	-->	etchstray
  Russia	-->	Ussiaray
  Athena	-->	Athenaway

A Sample Run

Input file: Frost.txt

Command to execute the program:

  java PigLatin Frost.txt out.txt
Here is out.txt:
Ethay Oadray Otnay Akentay

ybay Obertray Ostfray

Otway oadsray ivergedday inway away ellowyay oodway,
Andway orrysay Iway ouldcay otnay aveltray othbay
Andway ebay oneway avelertray, onglay Iway oodstay
Andway ookedlay ownday oneway asway arfay asway Iway ouldcay
Otay erewhay itway entbay inway ethay undergrowthway;
Enthay ooktay ethay otherway, asway ustjay asway airfay,
Andway avinghay erhapspay ethay etterbay aimclay,
Ecausebay itway asway assygray andway antedway earway;
Oughthay asway orfay atthay ethay assingpay erethay
Adhay ornway emthay eallyray aboutway ethay amesay,
Andway othbay atthay orningmay equallyway aylay
Inway eaveslay onay epstay adhay oddentray ackblay.
Ohway, Iway eptkay ethay irstfay orfay anotherway ayday!
Etyay owingknay owhay ayway eadslay onway otay ayway,
Iway oubtedday ifway Iway ouldshay everway omecay ackbay.
Iway allshay ebay ellingtay isthay ithway away ighsay
Omewheresay agesway andway agesway encehay:
Otway oadsray ivergedday inway away oodway, andway Iway--
Iway ooktay ethay oneway esslay aveledtray ybay,
Andway atthay ashay ademay allway ethay ifferenceday. 

Submitting:

Using the usual submission page, submit the file:
  PigLatin.java