Roke98

Ejercicio2-Tp0-UNJU

Aug 26th, 2022 (edited)
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.27 KB | None | 0 0
  1. package Practico0;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Random;
  5. import Practico0.Helper;
  6.  
  7. public class Ejercicio2 {
  8.  
  9.     public static void main(String[] args) {
  10.         // TODO Auto-generated method stub
  11.        
  12.         menu();
  13.  
  14.     }
  15.  
  16.     static void menu(){
  17.         Scanner sn = new Scanner(System.in);
  18.         boolean salir= false;
  19.         int opcion;
  20.        
  21.         while(!salir) {
  22.             System.out.println("1- Ingresar valores");
  23.             System.out.println("2- Generar valores aleatorios");
  24.             System.out.println("3- Fin");
  25.            
  26.             try {
  27.                 System.out.println("Escriba una opcion");
  28.                 opcion = sn.nextInt();
  29.                
  30.                 switch(opcion){
  31.                
  32.                 case 1:
  33.                     String opcion2;
  34.                     int angulo, contObt = 0, contCon = 0;
  35.                     System.out.println("INGRESAR VALORES");
  36.                     do {
  37.                         angulo=ingresarValor();
  38.                         verAngulo(angulo);
  39.                         if((angulo>90)&&(angulo<180)) {
  40.                             contObt ++;
  41.                         }if ((angulo > 180)) {
  42.                             contCon++;
  43.                         }
  44.                        
  45.                         System.out.println("Desea ingresar otro angulo??(s/n)");
  46.                         opcion2 = sn.next();
  47.                     }while(!opcion2.equals("n"));
  48.                     System.out.println("Se ingresaron un total de " + contObt + " angulos obtusos");
  49.                     System.out.println("Se ingresaron un total de " + contCon + " angulos mayores a 180(Convexos)");
  50.                     espera();
  51.                     break;
  52.                 case 2:
  53.                     String opcion3;
  54.                     Random aleatorio = new Random();
  55.                     int contObt1 = 0, contCon1 = 0;
  56.                     do {
  57.                         int angulo1 = aleatorio.nextInt(360);
  58.                         System.out.println("El angulo generado es: " + angulo1);
  59.                         verAngulo(angulo1);
  60.                         if((angulo1>90)&&(angulo1<180)) {
  61.                             contObt1 ++;
  62.                         }if ((angulo1 > 180)) {
  63.                             contCon1 ++;
  64.                         }
  65.                        
  66.                         System.out.println("Desea generar otro angulo??(s/n)");
  67.                         opcion3 = sn.next();
  68.                     }while(!opcion3.equals("n"));
  69.                     System.out.println("Se generΓ³ un total de " + contObt1 + " angulos obtusos");
  70.                     System.out.println("Se generΓ³ un total de " + contCon1 + " angulos mayores a 180(Convexos)");
  71.                     espera();
  72.                     break;
  73.                 case 3:
  74.                     System.out.println("Gracias :D");
  75.                     salir = true;
  76.                     break;
  77.                 default:
  78.                     System.out.println("Opcion no valida");
  79.                 }
  80.             }catch(Exception e){
  81.                 System.out.println("Opcion no valida");
  82.                 sn.next();
  83.             }
  84.         }
  85.     }
  86.    
  87.    
  88.    
  89.     public static Integer ingresarValor() {
  90.         Helper help = new Helper();
  91.        
  92.         @SuppressWarnings("static-access")
  93.         Integer num = help.getInteger("Ingrese un numero positivo ");
  94.        
  95.         return num;
  96.     }
  97.    
  98.     public static void verAngulo(int angulo){
  99.         int compl;
  100.         if(angulo < 90){
  101.             System.out.println("El angulo es agudo");
  102.             compl = 90 - angulo;
  103.             System.out.println("su complemento es: " + compl);
  104.         }else {
  105.             if(angulo == 90){
  106.                 System.out.println("Es un angulo recto");
  107.             }else {
  108.                 if(angulo > 90 && angulo < 180) {
  109.                     int supl;
  110.                     System.out.println("El angulo es obtuso");
  111.                     supl = 180 - angulo;
  112.                     System.out.println("El sumplemento es: " + supl);
  113.                 }else {
  114.                     if(angulo == 180) {
  115.                         System.out.println("Es un angulo llano");
  116.                     }else {
  117.                         System.out.println("Otro tipo de angulo");
  118.                     }
  119.                 }
  120.             }
  121.         }
  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.    
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment