Roke98

Ejercicio6-Tp0-UNJU

Aug 26th, 2022 (edited)
1,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. package Practico0;
  2.  
  3. import Practico0.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.         menu(a,b,c);
  13.        
  14.     }
  15.  
  16.     public static void menu(int a,int b, int c) {
  17.                
  18.         Scanner sn = new Scanner(System.in);
  19.         boolean salir= false;
  20.         int opcion;
  21.        
  22.         while(!salir) {
  23.             System.out.println("1- Ingresar valores");
  24.             System.out.println("2- Generar valores aleatorios");
  25.             System.out.println("3- Fin");
  26.             try {
  27.                 System.out.println("Escriba una opcion");
  28.                 opcion = sn.nextInt();
  29.                 switch(opcion){
  30.                 case 1:
  31.                     String opcion2;
  32.                     do {
  33.                         asignar(a,b,c);
  34.                         System.out.println("Desea ingresar mas valores??(s/n)");
  35.                         opcion2 = sn.next();
  36.                     }while(!opcion2.equals("n"));
  37.                    
  38.                
  39.                     break;
  40.                 case 2:
  41.                     String opcion3;
  42.                     do {
  43.                         a = generarValor();
  44.                         b = generarValor();
  45.                         c = generarValor();
  46.                         System.out.println("Los valores generados son: " + a +" " +  b +" "+ c);
  47.                         triangulo(a,b,c);
  48.                         System.out.println("Desea generar otros valores??(s/n)");
  49.                         opcion3 = sn.next();
  50.                     }while(!opcion3.equals("n"));
  51.                    
  52.                     break;
  53.                 case 3:
  54.                     System.out.println("Gracais :D");
  55.                     salir = true;
  56.                     break;
  57.                 default:
  58.                     System.out.println("Opcion no valida");
  59.                     espera();
  60.                 }
  61.             }catch(Exception e){
  62.                 System.out.println("Opcion no valida");
  63.                 espera();
  64.             }
  65.         }  
  66.     }
  67.    
  68.    
  69.     public static void asignar(int a, int b, int c) {
  70.         a = ingresarValor();
  71.         if(a>0) {
  72.             b = ingresarValor();
  73.             if (b>0) {
  74.                 c = ingresarValor();
  75.                 if (c>0) {
  76.                     triangulo(a,b,c);
  77.                 }
  78.             }
  79.         }
  80.     }
  81.    
  82.     public static Boolean equilatero(int a, int b, int c) {
  83.         if ((a==b)&&(a==c)) {
  84.             return true;
  85.         }
  86.         return false;
  87.     }
  88.    
  89.     public static Boolean isoceles(int a, int b, int c) {
  90.         if((a==b)||(b==c)||(a==c)) {
  91.             return true;
  92.         }
  93.         return false;
  94.     }
  95.    
  96.     public static void triangulo(int a, int b, int c) {
  97.         if(teorema(a,b,c)) {
  98.             if(equilatero(a,b,c)) {
  99.                 System.out.println("Es un triangulo Equilatero");
  100.             }else {
  101.                 if(isoceles(a,b,c)) {
  102.                     System.out.println("Es un triangulo Isoceles");
  103.                 }else {
  104.                     System.out.println("Es un triangulo Escaleno");
  105.                 }
  106.             }
  107.            
  108.         }else {
  109.             System.out.println("No cumple el Teorema de Desigualdad de Triangulos");
  110.         }
  111.     }
  112.    
  113.     public static Boolean teorema (int a, int b, int c) {
  114.         if((a+b>c)&&(a+c>b)&&(b+c>a)) {
  115.             System.out.println("Cumple con el teorema");
  116.             return true;
  117.         }
  118.         return false;
  119.     }
  120.    
  121.    
  122.     public static Integer ingresarValor() {
  123.         Helper help = new Helper();
  124.        
  125.         @SuppressWarnings("static-access")
  126.         Integer num = help.getInteger("Ingrese un numero positivo ");
  127.        
  128.         return num;
  129.     }
  130.    
  131.    
  132.     public static Integer generarValor(){
  133.         Random numAl = new Random();
  134.         int num1 = numAl.nextInt(100);
  135.         return num1;
  136.     }
  137.    
  138.    
  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. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment