Advertisement
LEANDRONIEVA

Ejercicio6Nuevo

Sep 4th, 2022 (edited)
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.98 KB | None | 0 0
  1. package tp0nuevo;
  2.  
  3. import tp0.Helper;
  4. import java.util.Random;
  5. import java.util.Scanner;
  6.  
  7. public class Ejercicio6 {
  8.  
  9.     public static void main(String[] args) {
  10.         // TODO Auto-generated method stub
  11.         int a=0,b=0,c = 0;
  12.        
  13.         System.out.println("Ejercicio 6 - Tp 0");
  14.         menu(a,b,c);
  15.        
  16.     }
  17.  
  18.     @SuppressWarnings("static-access")
  19.     public static void menu(int a,int b, int c) {
  20.                
  21.         Helper op = new Helper();
  22.         boolean salir= false;
  23.         int opcion;
  24.        
  25.         while(!salir) {
  26.             System.out.println("1- Ingresar valores");
  27.             System.out.println("2- Generar valores aleatorios");
  28.             System.out.println("3- Fin");
  29.                
  30.             opcion = op.getInteger("Escriba una opcion");
  31.             switch(opcion){
  32.             case 1:
  33.                 Character opcion2;
  34.                 do {
  35.                     asignar(a,b,c);
  36.                     opcion2 = op.getCharacter("Desea ingresar mas valores??(s/n)");
  37.                 }while(!opcion2.equals('n'));
  38.  
  39.  
  40.                 break;
  41.             case 2:
  42.                 Character opcion3;
  43.                 do {
  44.                     a = generarValor();
  45.                     b = generarValor();
  46.                     c = generarValor();
  47.                     System.out.println("Los valores generados son: " + a +" " +  b +" "+ c);
  48.                     triangulo(a,b,c);
  49.                     System.out.println();
  50.                     opcion3 = op.getCharacter("Desea generar otros valores??(s/n)");
  51.                 }while(!opcion3.equals('n'));
  52.  
  53.                 break;
  54.             case 3:
  55.                 System.out.println("Gracias :D");
  56.                 salir = true;
  57.                 break;
  58.             default:
  59.                 System.out.println("Opcion no valida");
  60.                 espera();
  61.  
  62.  
  63.             }
  64.         }  
  65.     }
  66.  
  67.    
  68.     public static void asignar(int a, int b, int c) {
  69.         a = ingresarValor();
  70.         if(a>0) {
  71.             b = ingresarValor();
  72.             if (b>0) {
  73.                 c = ingresarValor();
  74.                 if (c>0) {
  75.                     triangulo(a,b,c);
  76.                 }
  77.             }
  78.         }
  79.     }
  80.    
  81.     public static Boolean equilatero(int a, int b, int c) {
  82.         if ((a==b)&&(a==c)) {
  83.             return true;
  84.         }
  85.         return false;
  86.     }
  87.    
  88.     public static Boolean isoceles(int a, int b, int c) {
  89.         if((a==b)||(b==c)||(a==c)) {
  90.             return true;
  91.         }
  92.         return false;
  93.     }
  94.    
  95.     public static void triangulo(int a, int b, int c) {
  96.         if(teorema(a,b,c)) {
  97.             if(equilatero(a,b,c)) {
  98.                 System.out.println("Es un triangulo Equilatero");
  99.             }else {
  100.                 if(isoceles(a,b,c)) {
  101.                     System.out.println("Es un triangulo Isoceles");
  102.                 }else {
  103.                     System.out.println("Es un triangulo Escaleno");
  104.                 }
  105.             }
  106.            
  107.         }else {
  108.             System.out.println("No cumple el Teorema de Desigualdad de Triangulos");
  109.         }
  110.     }
  111.    
  112.     public static Boolean teorema (int a, int b, int c) {
  113.         if((a+b>c)&&(a+c>b)&&(b+c>a)) {
  114.             System.out.println("Cumple con el teorema");
  115.             return true;
  116.         }
  117.         return false;
  118.     }
  119.    
  120.    
  121.     public static Integer ingresarValor() {
  122.         Helper help = new Helper();
  123.        
  124.         @SuppressWarnings("static-access")
  125.         Integer num = help.getPositiveInt("Ingrese un numero positivo ");
  126.        
  127.         return num;
  128.     }
  129.    
  130.    
  131.     public static Integer generarValor(){
  132.         Random numAl = new Random();
  133.         int num1 = numAl.nextInt(100);
  134.         return num1;
  135.     }
  136.    
  137.    
  138.     @SuppressWarnings("resource")
  139.     public static void espera (){ //Este modulo detiene el proceso hasta que el ususario precione "enter"
  140.         Scanner waitForKeypress = new Scanner(System.in);
  141.         System.out.print("Presiona la tecla Enter para continuar....");
  142.         waitForKeypress.nextLine();
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement