Advertisement
Jurado001

TP05ej4_Principal

Nov 2nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Principal {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner S = new Scanner(System.in);
  7.         BinarySearchTree<Product> ArbolProductos = new BinarySearchTree<Product>();
  8.         int opc;
  9.         do{
  10.             System.out.println("***** MENU *****\n1)Agregar elementos al arbol\n2)Mostrar el arbol\n3)Salir");
  11.             System.out.print("Seleccione una OPCION: ");
  12.             opc = S.nextInt();
  13.             switch (opc) {
  14.               case 1:
  15.                   CargarArbol(ArbolProductos);
  16.                   System.out.println();
  17.                   break;
  18.               case 2:
  19.                   MostrarArbol(ArbolProductos);
  20.                   break;
  21.               case 3:
  22.                   System.out.println("\nPROGRAMA FINALIZADO");
  23.                   break;
  24.               default:
  25.                   System.out.println("*** Opcion no valida ***");      
  26.             }
  27.         }while(opc != 3);
  28.     }      
  29.        
  30.     public static void CargarArbol(BinarySearchTree<Product> ArbolProductos) {
  31.         Scanner I = new Scanner(System.in);
  32.         char resp;
  33.         do {
  34.             System.out.print("\nCodigo: ");
  35.             int codigo = I.nextInt();
  36.             I.nextLine();
  37.             if(ArbolProductos.Contains(codigo)) {
  38.                 System.out.println("El codigo ingresado ya existe en el arbol...");
  39.             }
  40.             else {
  41.                 Product p1 = new Product();
  42.                 p1.setCodigo(codigo);
  43.                 System.out.print("Descripcion: ");
  44.                 p1.setDescripcion(I.nextLine());
  45.                 System.out.print("Precio ($): ");
  46.                 p1.setPrecio(I.nextDouble());
  47.                 ArbolProductos.Add(p1);
  48.             }
  49.             System.out.print("\n¿Cargar otro producto? (S/N): ");
  50.             resp = I.next().charAt(0);
  51.         }while(resp == 's'||resp == 'S');
  52.     }
  53.    
  54.     public static void MostrarArbol(BinarySearchTree<Product> ArbolProductos) {
  55.         System.out.println("\n_____________________________________________________\n***** Arbol de Productos *****");
  56.         ArbolProductos.InOrden();
  57.         System.out.println("_____________________________________________________\n");
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement