Advertisement
cotolonco

Menu [ Pilas simuladas con arreglo ]

Sep 24th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.27 KB | None | 0 0
  1. package pila;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Menu {
  6.    
  7.     public static void main( String[] args ){
  8.        
  9.         Scanner teclado = new Scanner( System.in );
  10.        
  11.         int opcion = 0;
  12.         Pila pila = null;
  13.        
  14.         while( opcion != 7 ){
  15.            
  16.             System.out.println( "\n1. Crear Pila" );
  17.             System.out.println( "2. Insertar Elemento");
  18.             System.out.println( "3. Eliminar Elemento" );
  19.             System.out.println( "4. Modificar Elemento" );
  20.             System.out.println( "5. Consultar Elemento" );
  21.             System.out.println( "6. Imprimir" );
  22.             System.out.println( "7. Salir" );
  23.             System.out.print( "Opcion > ");
  24.             opcion = teclado.nextInt();
  25.            
  26.             switch( opcion ){
  27.                 case 1:
  28.                     if ( pila == null ){
  29.                         System.out.print( "Ingrese tamano Pila: " );
  30.                         int tam = teclado.nextInt();
  31.                         pila = new Pila( tam );
  32.                         System.out.println( "Pila Creada!" );
  33.                     }else{
  34.                         System.out.println( "Pila ya creada" );
  35.                     }
  36.                     break;
  37.                 case 2:
  38.                     if ( pila != null ){
  39.                         System.out.print( "Ingrese elemento a insertar: " );
  40.                         int elemento = teclado.nextInt();
  41.                         pila.insertar( elemento );
  42.                     }else{
  43.                         System.out.println( "> No Hay Pila <" );
  44.                     }
  45.                     break;
  46.                 case 3:
  47.                     if ( pila != null ){
  48.                         System.out.print( "Ingrese elemento a eliminar: " );
  49.                         int elemento = teclado.nextInt();
  50.                         pila.eliminar( elemento );
  51.                     }else{
  52.                         System.out.println( "> No Hay Pila <" );
  53.                     }
  54.                     break;
  55.                 case 4:
  56.                     if ( pila != null ){
  57.                         System.out.print( "Ingrese elemento a cambiar: " );
  58.                         int valor = teclado.nextInt();
  59.                         System.out.print( "Ingrese nuevo valor: " );
  60.                         int nuevoValor = teclado.nextInt();
  61.                         pila.modificar( valor, nuevoValor );
  62.                     }else{
  63.                         System.out.println( "> No Hay Pila <" );
  64.                     }
  65.                     break;
  66.                 case 5:
  67.                     if ( pila != null ){
  68.                         System.out.print( "Ingrese posicion a consultar: " );
  69.                         int posicion = teclado.nextInt();
  70.                         pila.consultar( posicion );
  71.                     }else{
  72.                         System.out.println( "> No Hay Pila <" );
  73.                     }
  74.                     break;
  75.                 case 6:
  76.                     if ( pila != null )
  77.                         pila.imprimir();
  78.                     else
  79.                         System.out.println( "> No Hay Pila <" );
  80.                     break;
  81.             }
  82.            
  83.            
  84.         }
  85.        
  86.         System.exit( 0 );
  87.        
  88.     }
  89.    
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement