All pastes #179284 Raw Edit

Anonymous

public text v1 · immutable
#179284 ·published 2006-09-22 02:04 UTC
rendered paste body
/*
 * Aplicacion.java
 *
 * Created on 21 de septiembre de 2006, 22:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package practicoppr;

/**
 *
 * @author judaz
 */
public class Aplicacion {
       
    public static void main(String args[]){
        Arbol Arbol1 = new Arbol(null);
        carga(Arbol1);
        mostrarDestYNroCasa(Arbol1);
        
    }
    
private static void carga(Arbol Arbol1) {
        System.out.println("-- COMENZAREMOS CON LA CARGA DE LA CORRESPONDENCIA --");
        cargarArbol(Arbol1);
            
        boolean bandera = true;
        while(bandera == true){
            System.out.println("¿Desea cargar otra correspondencia?");
            System.out.println("1 = Si, 2 = No");
            int pregunta = In.readInt();
            switch(pregunta){
                case 1: cargarArbol(Arbol1); break;
                case 2: System.out.println("-- FIN DE LA CARGA --"); bandera = false; break;
                default : System.out.println("-- Respuesta invalida, intente de vuelta --"); break;
            }
        }
    }
    
private static void cargarArbol(Arbol Arbol1) {   
        int tipo = 0;
        boolean bandera = true;
        while(bandera == true){
            System.out.println("¿Que tipo de correspondencia va a cargar?");
            System.out.println("1 = Certificada; 2 = Encomienda, 3 = Simple");
            tipo = In.readInt();
            if(tipo == 1 || tipo == 2 || tipo == 3){
                bandera = false;
            }
            else{
                System.out.println("-- Tipo de encomienda Invalido, intente de vuelta --");
            }
        }
        
        System.out.println("¿Cual es el nombre del destinatario?");
        String destinatario = In.readLine();
        
        System.out.println("¿Cual es el peso de la correspondencia?");
        float peso = In.readFloat();
        
        System.out.println("¿Cual es el numero de casa?");
        int nroCasa = In.readInt();
        
        switch(tipo){
            case 1: {
                System.out.println("-- Creando Correspondencia Certficiada --");
                bandera = true;
                int prioridad = 0;
                while(bandera == true){
                    System.out.println("¿Cual es la proridad de la correspondencia?");
                    prioridad = In.readInt();
                    if(prioridad > 0 && prioridad < 11){
                        bandera = false;
                    }
                    else{
                        System.out.println("-- Prioridad invalida, intente de vuelta --");
                    }
                }
                
                System.out.println("¿Cual es el peso del sobre?");
                float pesoSobre = In.readFloat();
                
                Correspondencia Correspondencia1 = new Certificada(destinatario, peso, nroCasa, prioridad, pesoSobre);
                
                Arbol1.insertar(Correspondencia1);
            System.out.println("-- Correspondencia Certficiada Creada --");
            } break;
            
            case 2: {
                System.out.println("-- Creando Encomienda --");
                bandera = true;
                int tipoCaja = 0;
                while(bandera == true){
                    System.out.println("¿Cual es el tipo de caja para la correspondencia?");
                    System.out.println("1 = Pequeña; 2 = Mediana; 3 = Grande");
                    tipoCaja = In.readInt();
                    if(tipoCaja == 1 || tipoCaja == 2 || tipoCaja == 3){
                        bandera = false;
                    }
                    else{
                        System.out.println("-- Tipo de caja invalida, intente de vuelta --");
                    }
                }
                
                Correspondencia Correspondencia1 = new Encomienda(destinatario, peso, nroCasa, tipoCaja);
                Arbol1.insertar(Correspondencia1);
            System.out.println("-- Encomienda Creada --");
            } break;
            
            case 3: {
                System.out.println("-- Creando Correspondencia Simple --");
                Correspondencia Correspondencia1 = new Simple(destinatario, peso, nroCasa);
                Arbol1.insertar(Correspondencia1);
                System.out.println("-- Correspondencia Simple Creada --");
            }
        }
    }

private static void mostrarDestYNroCasa(Arbol Arbol1){
        System.out.println("¿De que forma quiere recorrer el arbol para mostrar la informacion?");
        System.out.println("¿1 = PreOrden; 2 = PostOrden; 3 = Orden Central?");
        int recorrido = In.readInt();
        boolean bandera = true;
        while (bandera == true) {
            if(recorrido == 1 || recorrido == 2 || recorrido == 3){
                Arbol1.mostrarVisita(recorrido);
                bandera = false;        
            }
            else {
                
                System.out.println("Tipo de recorrido invalido, intente de vuelta");        
            }
        }
    }
}