Advertisement
andresnogales

Menu.java

Sep 15th, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1.  
  2. /*
  3.  * Clase que instancia un objeto menu
  4.  * Recibe como parámetro constructor una arreglo de strings con las
  5.  * opciones a mostrar por pantalla
  6.  */
  7.  
  8. public class Menu {
  9.     private String[] options;
  10.  
  11.     public Menu(String[] options) {
  12.         this.options = options;
  13.     }
  14.  
  15.     public int getOption() {
  16.         int option;    
  17.         do{
  18.             System.out.println(System.lineSeparator().repeat(50));
  19.             System.out.println("----------------------------------");
  20.             System.out.println("    Opciones disponibles");
  21.             System.out.println("----------------------------------");
  22.            
  23.             for (int i = 0; i < options.length; i++) {
  24.                 System.out.println(String.format(" %d. %s",(i+1),options[i]));
  25.             }
  26.            
  27.             System.out.println("\n 0. Salir");
  28.             System.out.println("----------------------------------");
  29.            
  30.             option = Helper.getInt("\nIngrese una opción: ");
  31.            
  32.             if (option == 0) return option;
  33.            
  34.             if(option > options.length || option < 0) {
  35.                 System.out.println("No hay opción para lo ingresado");
  36.                 Helper.pressEnterKeyToContinue();
  37.             }
  38.         }while(option > options.length || option < 0);
  39.         return option;
  40.     }
  41.  
  42.     public void setOptions(String[] options) {
  43.         this.options = options;
  44.     }
  45.    
  46.    
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement