Advertisement
andresnogales

Main6.java

Sep 1st, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. public class Main6 {
  2.  
  3.     public static void main(String[] args){
  4.         int a = 0,b = 0,c = 0;
  5.         boolean repeat = true;
  6.        
  7.         while(repeat) {        
  8.             switch(menu()) {
  9.             case 1:
  10.                 //Ingreso por teclado
  11.                 a = Helper.getPositiveInt("Ingrese un número a: ");
  12.                 b = Helper.getPositiveInt("Ingrese un número b: ");           
  13.                 c = Helper.getPositiveInt("Ingrese un número c: ");   
  14.                 break;
  15.             case 2:
  16.                 //Generación de numeros aleatorios
  17.                 a = Helper.randomInt(1,100);
  18.                 b = Helper.randomInt(1,100);
  19.                 c = Helper.randomInt(1,100);
  20.                
  21.                 System.out.println("Números generados: a="+ a + " b=" + b + " c=" + c);
  22.                 pressEnterKeyToContinue();
  23.                 break;
  24.             case 3:
  25.                 //Código que hace lo que se solicita en el ejercicio.
  26.                 setTriangle(a,b,c);
  27.                 break;
  28.             case 4:
  29.                 System.out.println("Programa finalizado");
  30.                 repeat = false;
  31.                 break;
  32.             }                      
  33.         }
  34.     }
  35.    
  36.     public static int menu() {
  37.        
  38.         int option;
  39.        
  40.         do{
  41.             System.out.println(System.lineSeparator().repeat(50));
  42.             System.out.println("----------------------------------");
  43.             System.out.println("    Opciones disponibles");
  44.             System.out.println("----------------------------------");
  45.             System.out.println(" 1. Ingresar datos");
  46.             System.out.println(" 2. Generar datos aleatorios");
  47.             System.out.println(" 3. Determinar triángulo");
  48.             System.out.println("\n 4. Salir");
  49.             System.out.println("----------------------------------");
  50.            
  51.             option = Helper.getInt("\nIngrese una opción: ");
  52.             if(option > 4 || option < 1) {
  53.                 System.out.println("No hay opción para lo ingresado");
  54.             }
  55.         }while(option > 4 && option < 1);
  56.  
  57.         return option;
  58.     }
  59.    
  60.  
  61.     public static void pressEnterKeyToContinue()
  62.     {
  63.         System.out.println("\nPulse una tecla para continuar...");
  64.         Helper.scanner.nextLine();
  65.     }
  66.  
  67.     public static void setTriangle(int a, int b, int c) {
  68.         if(a != 0 && b != 0 && c != 0) {
  69.             try {
  70.                 Triangle triangle = new Triangle(a,b,c);
  71.                 System.out.println(triangle.toString());
  72.             } catch (TriangleException e) {
  73.                 System.out.println("a="+ a + " b=" + b + " c=" + c);
  74.                 System.out.println("No cumple el Teorema de la desigualdad del triángulo");
  75.             }          
  76.         }else {
  77.             System.out.println("Primero cargue valores");
  78.         }
  79.         pressEnterKeyToContinue();
  80.     }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement