Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Principal {
- public static void main(String[] args) {
- Scanner S = new Scanner(System.in);
- BinarySearchTree<Product> ArbolProductos = new BinarySearchTree<Product>();
- int opc;
- do{
- System.out.println("***** MENU *****\n1)Agregar elementos al arbol\n2)Mostrar el arbol\n3)Salir");
- System.out.print("Seleccione una OPCION: ");
- opc = S.nextInt();
- switch (opc) {
- case 1:
- CargarArbol(ArbolProductos);
- System.out.println();
- break;
- case 2:
- MostrarArbol(ArbolProductos);
- break;
- case 3:
- System.out.println("\nPROGRAMA FINALIZADO");
- break;
- default:
- System.out.println("*** Opcion no valida ***");
- }
- }while(opc != 3);
- }
- public static void CargarArbol(BinarySearchTree<Product> ArbolProductos) {
- Scanner I = new Scanner(System.in);
- char resp;
- do {
- System.out.print("\nCodigo: ");
- int codigo = I.nextInt();
- I.nextLine();
- if(ArbolProductos.Contains(codigo)) {
- System.out.println("El codigo ingresado ya existe en el arbol...");
- }
- else {
- Product p1 = new Product();
- p1.setCodigo(codigo);
- System.out.print("Descripcion: ");
- p1.setDescripcion(I.nextLine());
- System.out.print("Precio ($): ");
- p1.setPrecio(I.nextDouble());
- ArbolProductos.Add(p1);
- }
- System.out.print("\n¿Cargar otro producto? (S/N): ");
- resp = I.next().charAt(0);
- }while(resp == 's'||resp == 'S');
- }
- public static void MostrarArbol(BinarySearchTree<Product> ArbolProductos) {
- System.out.println("\n_____________________________________________________\n***** Arbol de Productos *****");
- ArbolProductos.InOrden();
- System.out.println("_____________________________________________________\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement