/*******************************************************************
 * Program:  Catch 22 Letter Censoring
 * Author:   Mark Rich, richm@cs.wisc.edu
 * Date:     3/30/2000
 *******************************************************************/
import javabook.*;

/**
 * Among the many insane happenings in the book "Catch-22" by
 * Joseph Heller is the censoring of letters by hospital inhabitants.
 * Yossarian is one of these insane sick inhabitants, and his antics
 * in censoring becomes one of the main themes of the book.  To
 * quote from page 8, 
 *   
 *   After the first day he had no curiosity at all.  To break the 
 *   monotony he invented games.  Death to all modifiers, he delcared
 *   one day, and out of every letter that passed through his hands 
 *   went every adverb and adjective.  The next day he made war on 
 *   articles.  He reached a much higher plane of creativity the following
 *   day when he blacked out everything in the letters by "a", "an", 
 *   and "the".  That erected more dynamic intralinear tensions, he felt,
 *   and in just about every case left a message far more universal. 
 *   
 * This program imitates Yossarian's censoring behavior with Strings
 * and StringBuffers and the Filter class.  The user inputs a letter
 * they're trying to send home, as well as the characters Yossarian
 * will be deleting today.  The letter is passed into Yossarian, altering
 * its contents, and the resulting message is displayed on the screen.
 */
class Catch22 {

    public static void main(String[] args) {
	
	// Declare and create the necessary javabook Objects
	MainWindow mw = new MainWindow();
	InputBox in = new InputBox(mw);
	OutputBox out = new OutputBox(mw);
	mw.show();
	out.show();

	// Ask the user for the attempted message and the 
	// characters to filter
	String str = in.getString("What is your letter home?" + 
				  " (one line please)");
	String fil = in.getString("What will Yossarian delete today?");
	
	// Declare and create the Filter object and the StringBuffer object
	Filter yossarian = new Filter(fil);
	StringBuffer strbf = new StringBuffer(str);

	// Display to the screen the original letter home
	out.printLine("Original letter is:");
	out.printLine(strbf);

	// Have yossarian edit your letter.
	yossarian.censor(strbf);

	// Now display the altered letter
	out.printLine("After Yossarian's censoring, the remaining letter is:");
	out.printLine(strbf);
    }
}

