Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Clase que instancia un objeto menu
- * Recibe como parámetro constructor una arreglo de strings con las
- * opciones a mostrar por pantalla
- */
- public class Menu {
- private String[] options;
- public Menu(String[] options) {
- this.options = options;
- }
- public int getOption() {
- int option;
- do{
- System.out.println(System.lineSeparator().repeat(50));
- System.out.println("----------------------------------");
- System.out.println(" Opciones disponibles");
- System.out.println("----------------------------------");
- for (int i = 0; i < options.length; i++) {
- System.out.println(String.format(" %d. %s",(i+1),options[i]));
- }
- System.out.println("\n 0. Salir");
- System.out.println("----------------------------------");
- option = Helper.getInt("\nIngrese una opción: ");
- if (option == 0) return option;
- if(option > options.length || option < 0) {
- System.out.println("No hay opción para lo ingresado");
- Helper.pressEnterKeyToContinue();
- }
- }while(option > options.length || option < 0);
- return option;
- }
- public void setOptions(String[] options) {
- this.options = options;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement