/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author mhussain3
 */
public class TreeDemo {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        insertNode();
        Tree tree = new Tree();

// replace here 
  // tree.insert("C12",1);
        
        Scanner sc = new Scanner(System.in);
        String input;
        boolean run = true;
        do {
            System.out.println("***********************************************");
            System.out.println("For insertion Press : 1");
            System.out.println("For Searching Press : 2");
           // System.out.println("For printing  Tree  : 3");
            System.out.println("Press Any other key to quit");
            System.out.println("***********************************************");
            System.out.println();
            input = sc.next().trim();
            if (input.equals("1")) {

                int value = -1;
                String cell = "";
                boolean isnumeric = false;
                do {
                    try {
                        System.out.println("Enter Cell Value");
                        value = Integer.parseInt(sc.next().trim());
                        System.out.println("Enter Cell Name");
                        cell = sc.next().trim().toUpperCase();
                        if (tree.cellArray.contains(cell)) {
                            tree.insert(cell, value);
                            isnumeric = true;
                        } else {
                            System.out.println("Cell Name should be in ");
                            for (int i = 0; i < tree.cellArray.size(); i++) {
                                System.out.print(tree.cellArray.get(i) + "\t");
                            }
                            System.out.println();
                        }
                    } catch (Exception ex) {
                        System.out.println("Value should be numeric"+ex.getMessage());
                    }
                } while (!isnumeric);

            } else if (input.equals("2")) {
                System.out.println("Enter Value to Search");
                int value = -1;
                boolean isnumeric = false;
                do {
                    try {
                        value = Integer.parseInt(sc.next());
                        isnumeric = true;
                    } catch (Exception ex) {
                        System.out.println("Value should be numeric"+ex.getMessage());
                    }
                } while (!isnumeric);

                tree.searchObject(value);
            } else if (input.equals("3")) {
                tree.printTree();
            } else {
                run = false;
            }

        } while (run);


        //tree.printTable();

        //tree.insert("C1", 1);
        //tree.printTree();
//        tree.insert("C2", 1);
//        tree.insert("C3", 3);
//        tree.insert("C2", 4);
//        tree.insert("C5", 5);
//        tree.insert("C2", 6);
//        tree.insert("C7", 7);
//        tree.insert("C2", 8);
//        tree.insert("C9", 9);
//        tree.insert("C8", 0);
//        tree.insert("C6", 12);
//        tree.insert("C2", 13);
//        tree.insert("C2", 31);
//        tree.insert("C9", 33);
//
//        tree.printTree();
  //     tree.searchObject(36);



    }
    public static void insertNode()
    {
         //Tree tree = new Tree();
         //tree.insert("C1", 1);
        //tree.searchObject(36);
    }

}
