Advertisement
LEANDRONIEVA

Ejercicio2Tp0

Aug 30th, 2022 (edited)
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. package tp0nuevo;
  2.  
  3. import tp0.Helper;
  4.  
  5. public class Tp0ejercicio2 {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.  
  10.         System.out.println("Ejercicio 2 Tp0");
  11.        
  12.         int op=0;
  13.         int n = ingresarCantidad();
  14.        
  15.         while (op != 3&op != 2 &op != 1) {
  16.             op = opcion();
  17.        
  18.             switch (op) {
  19.             case 1:
  20.                     evaluarAngulo(n,true);
  21.  
  22.                 System.out.println("Finalizando programa... Adiós!");
  23.                 break;
  24.             case 2:
  25.                     evaluarAngulo(n,false);
  26.                
  27.                 System.out.println("Finalizando programa... Adiós!");
  28.                 break;
  29.             case 3:
  30.                 System.out.println("Programa Terminado");
  31.                 break;
  32.             default:
  33.                 System.out.println("No es una opción correcta ");
  34.                 break;
  35.             }
  36.         }
  37.     }
  38.     @SuppressWarnings("static-access")
  39.     public static Integer ingresarCantidad() {
  40.         Helper numero = new Helper();
  41.         int n = numero.getPositiveInt("Ingrese la cantidad de ángulos que desea generar");
  42.        
  43.         return n;
  44.     }
  45.  
  46.     @SuppressWarnings("static-access")
  47.     public static int opcion() {
  48.         Helper numero = new Helper();
  49.         System.out.println("Desea generar ángulos aleatoriamente o ingresar manualmente?");
  50.         System.out.println("1. Aleatorio");
  51.         System.out.println("2. Manual");
  52.         System.out.println("3. Salir");
  53.        
  54.         Integer opcion = numero.getInteger("Ingrese una opción","Ingrese un número ");
  55.        
  56.         return opcion;
  57.     }
  58.     public static Integer aleatorio() {
  59.         Integer angulo = (int) (Math.random()*100);
  60.         System.out.println("Su ángulo generado aleatoriamente es = "+angulo);
  61.        
  62.         return angulo;
  63.     }
  64.     @SuppressWarnings("static-access")
  65.     public static Integer manual() {
  66.         Helper entero = new Helper();
  67.         Integer angulo = entero.getInteger("Ingrese el valor del ángulo (debe ser un número entero)");
  68.    
  69.         return angulo;
  70.     }
  71.     public static boolean esAgudo(int angulo) {
  72.         if (angulo>0&angulo<90) return true;
  73.         return false;
  74.     }
  75.     public static boolean esObtuso(int angulo) {
  76.         if (angulo>90&&angulo<180) return true;
  77.         return false;
  78.     }
  79.     public static boolean esConvexo(int angulo) {
  80.     if (angulo>180) return true;
  81.     return false;
  82.     }
  83.  
  84.     public static void evaluarAngulo(int n, boolean b) {
  85.         int cont1 = 0, cont2 = 0, angulo = 0;
  86.  
  87.         for (int i = 0; i<n; i++) {
  88.             if (b){
  89.             angulo = aleatorio();
  90.             }else{
  91.             angulo = manual()}
  92.             if (angulo==360) {
  93.                 System.out.println("Es un giro");
  94.             }else if (angulo>360) {
  95.                 System.out.println("Es mas de un giro!");
  96.             }else {
  97.                 if (esAgudo (angulo)) {
  98.                     int complementario = 90-angulo;
  99.                     System.out.println("Es un ángulo agudo ");
  100.                     System.out.println("Ángulo complementario = "+complementario);
  101.                 }else if (esObtuso(angulo)) {
  102.                     cont1++;
  103.                     int suplementario = 180-angulo;
  104.                     System.out.println("Es un ángulo obtuso ");
  105.                     System.out.println("Ángulo suplementario = "+suplementario);
  106.                 }else if (esConvexo(angulo)){
  107.                     cont2++;
  108.                     System.out.println("Es otro ángulo");
  109.                 }else if (angulo==90) {
  110.                     System.out.println("Es un ángulo recto ");
  111.                 }else if (angulo==180) {
  112.                     System.out.println("Es un ángulo llano ");
  113.                 }
  114.             }
  115.         }
  116.         System.out.println("obtusos "+cont1);
  117.         System.out.println("convexos "+cont2);
  118.        
  119.     }
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement