Main {

{{

  //constants  
  private static int QUIT = 4;
  private static String FILE_IN = "program.output";
  private static String FILE_OUT = "program.output";
  public static String divider = "--------------------------------------------";

  //private members
  private static FileInputStream fis;   //file to read in bank

  //public members
  public static Bank b;                //the one bank instance
  public static BufferedReader stdin;   //used by all classes to get user input
}}

  public static void main(String args[]) throws Exception {{

    /* This program is designed to be used by a bank. It holds functionality
      needed to run a bank with several branches */

      //set up members
      fis = new FileInputStream(FILE_IN);
      b = Bank.parse(fis);

      stdin = new BufferedReader(new InputStreamReader(System.in));

      //show menu and get user choice
      int choice = 0;	
      while (choice != QUIT){
	  try{
	      showMenu();
	      choice = getChoice();
	      doMenuChoice(choice);
	  }
	  catch(Exception e){
	      System.out.println("Error in main: " + e.toString());
	      e.printStackTrace();
	  }
      }
      b.print();
      writeOutputToFile();
      //b.display();
  }}

  public static int getChoice(){{

    /* This function will be used by all classes to get a menu choice 
     output: int representing the user's choice*/

    Integer choice = new Integer(0);    
    try{choice = new Integer(stdin.readLine());}
    catch (Exception e){System.out.println("Please enter a number");}
    return choice.intValue();
  }}

  private static void showMenu(){{

    /* This function just displays a menu */

    System.out.println(divider);
    System.out.println("Select a menu option:");
    System.out.println("1. Add a banking unit");
    System.out.println("2. Work with a banking unit");
    System.out.println("3. View all banking units");
    System.out.println("4. Quit");	

  }}

  private static void doMenuChoice(int choice) throws IOException{{
	
      /* This function will execute a menu choice 
	 input: choice - the choice entered by the user */

      if (choice == 1) b.addBusinessUnit();
      else if (choice == 2) b.modifyBusinessUnit();
      else if (choice == 3) b.viewUnits();
      else if (choice != QUIT) System.out.println("Invalid choice");

  }}

  private static void writeOutputToFile(){{

      /* writes the final data structure to FILE_OUT */

      FileOutputStream fos;      //stream to file we will write to
      PrintVisitor pv = null;           //used to write to the file

      try{
	  fos  = new FileOutputStream(FILE_OUT);
	  pv = new PrintVisitor(new PrintWriter(fos));
      }
      catch (Exception e) {System.out.println("Error writing output " + e.toString());}

      pv.start();
      b.everything(pv);
      pv.finish();

  }}

}//end Main

Bank { traversal everything(PrintVisitor){ to *;}}