Advertisement
adaptingear

Nodocola1

Sep 2nd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.58 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package nodocola;
  7.  
  8. import javax.swing.JOptionPane;
  9.  
  10. /**
  11.  *
  12.  * @author USER
  13.  */
  14. public class NodoCola {
  15.  
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.    
  21.     public static void main(String[] args) {
  22.         // TODO code application logic here
  23.         int opcion=0, elemento=0;
  24.         Pila pilita=new Pila();
  25.         do{
  26.             try{
  27.                 opcion = Integer.parseInt(JOptionPane.showInputDialog(null,
  28.                         "1. Empujar un elemento en la pila\n "
  29.                         + "2. Sacar un elemento de la pila \n"
  30.                         + "3. ¿La pila esta vacia?\n"
  31.                         + "4. Que elemento esta en la cima?\n"
  32.                         + "5. Tamaño de la pila\n"
  33.                         + "6. Vaciar pila\n"
  34.                         + "7. Salir \n"
  35.                         + "Que deseas hacer?", "Menu de opciones",
  36.                         JOptionPane.INFORMATION_MESSAGE));
  37.                        switch (opcion) {
  38.                            
  39.                            case 1:
  40.                                elemento = Integer.parseInt(JOptionPane.showInputDialog(null,
  41.                                        "Ingresa el elemento a empujar en la pila", "Apilando datos",
  42.                                        JOptionPane.INFORMATION_MESSAGE));
  43.                              pilita.empujar(elemento);
  44.                              break;
  45.                                
  46.                            case 2:
  47.                                if(!pilita.estaVacia()){
  48.                                    JOptionPane.showMessageDialog(null, "el elemento obtenido es"
  49.                                    + pilita.sacar(),
  50.                                            "Obteniendo datos de la pila", JOptionPane.INFORMATION_MESSAGE);                                  
  51.                                }else{
  52.                                    JOptionPane.showMessageDialog(null, "La pila esta vacia",
  53.                                            "Pila vacia", JOptionPane.INFORMATION_MESSAGE);
  54.                                }
  55.                                break;                              
  56.                            case 3:
  57.                                if(pilita.estaVacia()){
  58.                                     JOptionPane.showMessageDialog(null, "Si, La pila esta vacia",
  59.                                             "Pila Vacia", JOptionPane.INFORMATION_MESSAGE);
  60.                                }else{
  61.                                    JOptionPane.showMessageDialog(null, "No, La pila no esta vacia",
  62.                                            "La pila contiene datos", JOptionPane.INFORMATION_MESSAGE);
  63.                                }
  64.                            break;                            
  65.                            case 4:
  66.                                if(!pilita.estaVacia()){
  67.                                    JOptionPane.showMessageDialog(null, "El elemento que se encuentra en la cima" + pilita.cima(),
  68.                                            "Cima de la pila", JOptionPane.INFORMATION_MESSAGE);
  69.                                }else{
  70.                                    JOptionPane.showMessageDialog(null, "No hay elemento en la cima de la pila, razon: esta vacia",
  71.                                            "Pila vacia", JOptionPane.INFORMATION_MESSAGE);
  72.                                }
  73.                            break;                              
  74.                            case 5:
  75.                              JOptionPane.showMessageDialog(null, "El tamaño de la pila es" + pilita.tamanioPila(),
  76.                                            "tamaño de la pila", JOptionPane.INFORMATION_MESSAGE);  
  77.                                  
  78.                            break;                          
  79.                            case 6:
  80.                                if(!pilita.estaVacia()){
  81.                                        pilita.limpiarPila();                          
  82.                                    JOptionPane.showMessageDialog(null, "La pila se ha vaciado",
  83.                                            "Vaciando Pila", JOptionPane.INFORMATION_MESSAGE);
  84.                                    break;
  85.                              
  86.                                }else{
  87.                                                                        JOptionPane.showMessageDialog(null, "La pila esta vacia, no hay nada que vaciar",
  88.                                             "Pila vacia", JOptionPane.INFORMATION_MESSAGE);
  89.                                                                        break;
  90.                                }
  91.                            case 7:
  92.                                  JOptionPane.showMessageDialog(null, "Aplicacion finalizada",
  93.                                            "Fin", JOptionPane.INFORMATION_MESSAGE);
  94.                                break;
  95.                            default:
  96.                                  JOptionPane.showMessageDialog(null, "Opcion incorrecta",
  97.                                            "Error", JOptionPane.INFORMATION_MESSAGE);
  98.  
  99.                            break;                                                                                          
  100.               }
  101.                        
  102.             }catch(NumberFormatException n){
  103.                  JOptionPane.showMessageDialog(null, "Error" + n.getMessage());
  104.             }
  105.         }while(opcion!=7);
  106.     }
  107.    
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement