title: Creating a driver program
body: <p>My course work requires me to create driver programs to test my classes. Apparently, a driver program is simply just a class with a main method that test a separate class. By separate I mean that the driver program will test a class that is not within the driver's class. How do I use a class in my driver program? Do I import this class? If so how do I import one of my own classes? The driver program should be implemented in exactly the same way as it would be if the class contract and main method were within the same class. I am not interested in implementing them both in the same class, because they must be separate.</p>
  
  <p>How can I use the class BST in this TestBST class? The line <code>BST&lt;String&gt; bst = new BST&lt;String&gt;(tempHold);</code> does not work.</p>
  
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.ArrayList;
  import java.util.Scanner;
  
  import javax.swing.JOptionPane;
  
  /*    
   * This class implements a binary search tree. I have created addition methods and a main method
   * in order to test the program. This program includes methods for counting the nodes on all levels
   * of the tree. Getting tree height, ace values, node balance level, and balancing the tree.
   * @param &lt;E&gt;
   */
  public class TestBST {
  
      public static void main(String[] args) {
  
          System.out.println("David Jennings CMSC350 Project 3");
          File input = new File("BSTINPUT.txt");
          try {
  
              Scanner reader = new Scanner(input);
              ArrayList&lt;String&gt; valuePasser = new ArrayList&lt;String&gt;();
              String[] tempStorage;
              while (reader.hasNext()) {
                  String line = reader.nextLine();
                  tempStorage = (line.split(";"));
                  for (int i = 0; i &lt; tempStorage.length; i++) {
                      valuePasser.add(tempStorage[i]);
                  }
              }
  
              String[] tempHold = new String[valuePasser.size()];
              for (int i = 0; i &lt; valuePasser.size(); i++) {
                  tempHold[i] = valuePasser.get(i);
              }
  
              BST&lt;String&gt; bst = new BST&lt;String&gt;(tempHold);
              int actionChoice = 12;
              do {
                  try {
  
                      actionChoice = Integer.parseInt(JOptionPane.showInputDialog("Please choose action: \n "
                              + "(0) Exit program\n (1) In-order tree traversal\n (2) Pre-order tree traversal\n (3) CalculateACE\n"
                              + "(4) CalculateMinAce\n (5) CalculateMaxACE\n (6) NumberOfNodesAllLevels\n  (7) TreeHeight\n (8) NodeBalanceLevel\n "
                              + "(9) NeedsBalancing\n (10) BalanceBST\n (11) insert value\n"));
                  } catch (NumberFormatException e) {
                      JOptionPane.showMessageDialog(null, "Please only exit program by using input of 0 \nSorry, program only takes integer values between 0 and 10. Please restart program");
                      System.exit(1);
                  }
  
                  if (actionChoice &lt; 0 || actionChoice &gt; 11) {
                      JOptionPane.showMessageDialog(null, "Please only exit program by using input of 0 \nSorry, program only takes integer values between 0 and 10. please restart program");
                      System.exit(1);
                  }
  
                  if (actionChoice == 1) {
                      System.out.println(" In-order tree values: ");
                      bst.inorder();
                      System.out.println(" ");
                  }
  
                  if (actionChoice == 2) {
                      System.out.println("pre-order tree values: ");
                      bst.preorder();
                      System.out.println(" ");
                  }
  
                  if (actionChoice == 3) {
                      System.out.println("Tree ACE value : " + bst.calculateAce());
                      System.out.println(" ");
                  }
                  if (actionChoice == 4) {
                      System.out.println("Tree minACE value : " + bst.calculateMinAce());
                      System.out.println(" ");
                  }
                  if (actionChoice == 5) {
                      System.out.println("Tree maxACE value : " + bst.calculateMaxAce());
                      System.out.println(" ");
                  }
                  if (actionChoice == 6) {
                      System.out.println(" The number of nodes at all levels of the tree are:");
                      for (int i = 0; i &lt; bst.treeHeight(); i++) {
                          System.out.println("Number of nodes at level: " + i);
                          System.out.println(bst.numberOfNodesAtLevel(i));
                      }
                      System.out.println(" ");
                  }
                  if (actionChoice == 7) {
                      System.out.println(" Current tree height: " + bst.treeHeight());
                      System.out.println(" ");
                  }
                  if (actionChoice == 8) {
                      System.out.println(" Node Balance Level: " + bst.nodeBalanceLevel());
                      System.out.println(" ");
                  }
                  if (actionChoice == 9) {
                      System.out.println(" Tree needs balancing?: " + bst.needsBalancing());
                      System.out.println(" ");
                  }
                  if (actionChoice == 10) {
                      bst.balanceBST();
                      System.out.println(" Balancing BST: " +"\n new balance level:" + bst.nodeBalanceLevel());
                      System.out.println(" ");
                  }
                  if (actionChoice == 11) {
                      bst.insert(JOptionPane.showInputDialog("Input integer to be added to tree: "));
                      System.out.println(" ");
                  }
  
              } while (actionChoice != 0);
  
          } catch (FileNotFoundException e) {
              System.out.println("File not found. Please connect BSTINPUT.txt file and restart program.");
          }
  
      }
  }
  </code></pre>