Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package nodocola;
- import javax.swing.JOptionPane;
- /**
- *
- * @author USER
- */
- public class NodoCola {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int opcion=0, elemento=0;
- Pila pilita=new Pila();
- do{
- try{
- opcion = Integer.parseInt(JOptionPane.showInputDialog(null,
- "1. Empujar un elemento en la pila\n "
- + "2. Sacar un elemento de la pila \n"
- + "3. ¿La pila esta vacia?\n"
- + "4. Que elemento esta en la cima?\n"
- + "5. Tamaño de la pila\n"
- + "6. Vaciar pila\n"
- + "7. Salir \n"
- + "Que deseas hacer?", "Menu de opciones",
- JOptionPane.INFORMATION_MESSAGE));
- switch (opcion) {
- case 1:
- elemento = Integer.parseInt(JOptionPane.showInputDialog(null,
- "Ingresa el elemento a empujar en la pila", "Apilando datos",
- JOptionPane.INFORMATION_MESSAGE));
- pilita.empujar(elemento);
- break;
- case 2:
- if(!pilita.estaVacia()){
- JOptionPane.showMessageDialog(null, "el elemento obtenido es"
- + pilita.sacar(),
- "Obteniendo datos de la pila", JOptionPane.INFORMATION_MESSAGE);
- }else{
- JOptionPane.showMessageDialog(null, "La pila esta vacia",
- "Pila vacia", JOptionPane.INFORMATION_MESSAGE);
- }
- break;
- case 3:
- if(pilita.estaVacia()){
- JOptionPane.showMessageDialog(null, "Si, La pila esta vacia",
- "Pila Vacia", JOptionPane.INFORMATION_MESSAGE);
- }else{
- JOptionPane.showMessageDialog(null, "No, La pila no esta vacia",
- "La pila contiene datos", JOptionPane.INFORMATION_MESSAGE);
- }
- break;
- case 4:
- if(!pilita.estaVacia()){
- JOptionPane.showMessageDialog(null, "El elemento que se encuentra en la cima" + pilita.cima(),
- "Cima de la pila", JOptionPane.INFORMATION_MESSAGE);
- }else{
- JOptionPane.showMessageDialog(null, "No hay elemento en la cima de la pila, razon: esta vacia",
- "Pila vacia", JOptionPane.INFORMATION_MESSAGE);
- }
- break;
- case 5:
- JOptionPane.showMessageDialog(null, "El tamaño de la pila es" + pilita.tamanioPila(),
- "tamaño de la pila", JOptionPane.INFORMATION_MESSAGE);
- break;
- case 6:
- if(!pilita.estaVacia()){
- pilita.limpiarPila();
- JOptionPane.showMessageDialog(null, "La pila se ha vaciado",
- "Vaciando Pila", JOptionPane.INFORMATION_MESSAGE);
- break;
- }else{
- JOptionPane.showMessageDialog(null, "La pila esta vacia, no hay nada que vaciar",
- "Pila vacia", JOptionPane.INFORMATION_MESSAGE);
- break;
- }
- case 7:
- JOptionPane.showMessageDialog(null, "Aplicacion finalizada",
- "Fin", JOptionPane.INFORMATION_MESSAGE);
- break;
- default:
- JOptionPane.showMessageDialog(null, "Opcion incorrecta",
- "Error", JOptionPane.INFORMATION_MESSAGE);
- break;
- }
- }catch(NumberFormatException n){
- JOptionPane.showMessageDialog(null, "Error" + n.getMessage());
- }
- }while(opcion!=7);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement