import java.util.Scanner; public class Solution { /** * Gets data from standard input */ private Scanner input; private boolean programIsRunning = false; /** * Start the execution of the solution * @param args Command line arguments */ public static void main(String[] args) { Solution solution = new Solution(); solution.run(); } /** * It runs the program. * The user will have the option to choose to insert a new value to the tree, to reset the tree or to * get the max depth of the tree. */ public void run() { input = new Scanner(System.in); RandomTree tree = new RandomTree(); programIsRunning = true; while(programIsRunning) { System.out.printf("Enter a number for one of the following options:%n" + "Option 1: Reset tree%n" + "Option 2: Insert an element%n" + "Option 3: Get the depth of the tree%n" + "Option 4: Finish running the program%n"); int option = Integer.parseInt(input.next()); runOption(tree, option); } } public void runOption(RandomTree tree, int option) { switch(option) { case 1: tree.resetTree(); break; case 2: System.out.print("Enter the value that you want to insert: "); int value = Integer.parseInt(input.next()); tree.insert(value, System.out); System.out.println(); break; case 3: System.out.println(tree.getTreeDepth()); break; case 4: programIsRunning = false; break; default: System.out.println("Invalid option"); } } }