Advertisement
Roke98

Ejercicio2-Tp0-UNju(Cambios)

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