import java.util.Scanner; public class TreeTest { public static void Menu(){ System.out.println ("1 - Insert a Value "); System.out.println ("2 - Print the Tree"); System.out.println ("3 - Quit"); } public static void main (String args []) { System.out.println ("Binary Search Trees"); Scanner scanner = new Scanner (System.in); Scanner scanner1 = new Scanner (System.in); Tree tree = new Tree (); boolean flag = true; int status = 0, choice = 0; while (flag){ Menu(); status = 0; try { choice = Integer.parseInt(scanner.nextLine()); } catch (Exception e){ System.out.println("Integers Only - Enter Again"); status = 1; } if (choice == 1) { System.out.println ("Input Value"); int input = scanner1.nextInt(); tree.insert (input); } else if (choice == 2){ if (tree.isEmpty()){ System.out.println ("The Tree is Empty"); } else{ tree.outputTree(); } } else if (choice == 3){ flag = false; System.out.println ("End of Program"); } else if (status == 0){ System.out.println ("Invalid Entry - Enter Again"); } System.out.println ("\n"); } } }