Advertisement
LEANDRONIEVA

Tp 0 ej 1 UNJU

Aug 20th, 2022 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.93 KB | None | 0 0
  1. package tp0nuevo;
  2.  
  3. import tp0.Helper;
  4.  
  5. public class tp0ejercicio1 {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         System.out.println("Ejercicio 1 - Tp 0");
  10.    
  11.         evaluar(); 
  12.     }
  13.     public static void evaluar() {
  14.         Float a,b,c,d;
  15.         Float menor_perimetro = 0.00f;
  16.         Float mayor_area = 0.00f;
  17.         int otros_poligonos = 0;
  18.        
  19.         a = ingresarParametro();
  20.         if (esPositivo(a)) {
  21.             System.out.println("Lado 1: "+a);
  22.             b = ingresarParametro();
  23.             if(esPositivo(b)) {
  24.                 System.out.println("Lado 2: "+b);
  25.                 c = ingresarParametro();
  26.                 if(esPositivo(c)) {
  27.                     System.out.println("Lado 3: "+c);
  28.                     d = ingresarParametro();
  29.                     if (esPositivo(d)) {
  30.                         System.out.println("Lado 4: "+d);
  31.                         if (esUnCuadrado(a,b,c,d)) {
  32.                             System.out.println("Es un cuadrado");
  33.                             Float perimetro = a*4;
  34.                             menor_perimetro = menor(menor_perimetro,perimetro);
  35.                             System.out.println("Perímetro = "+perimetro);
  36.                             evaluar();
  37.                         }else if (esUnRectangulo(a,b,c,d)){
  38.                             System.out.println("Es un rectángulo");
  39.                             Float area = 0.00f;
  40.                             if (a!=b) {
  41.                                 area = a*b;
  42.                             }else if (a!=c) {
  43.                                 area = a*c;
  44.                             }
  45.                             System.out.println("El área es = "+area);
  46.                             mayor_area = mayor(mayor_area,area);
  47.                             evaluar();
  48.                         }else{
  49.                             System.out.println("Es otro polígono");
  50.                             otros_poligonos++;
  51.                             evaluar();
  52.                         }
  53.                         devolverValores(menor_perimetro,mayor_area,otros_poligonos);
  54.                     }else {
  55.                         System.out.println("Programa terminado. Adios ");
  56.                     }
  57.                 }else {
  58.                     System.out.println("Programa terminado. Adios ");
  59.                 }              
  60.             }else {
  61.                 System.out.println("Programa terminado. Adios ");
  62.             }
  63.         }else {
  64.         System.out.println("Programa terminado. Adios ");
  65.         }
  66.        
  67.     }
  68.     public static Float ingresarParametro() {
  69.         Helper help = new Helper();
  70.        
  71.         @SuppressWarnings("static-access")
  72.         Float parametro = help.getFloat("Ingrese un número positivo para continuar ");
  73.         parametro = (float) (Math.round(parametro*100d)/100d);
  74.        
  75.         return parametro;
  76.     }
  77.     public static Boolean esUnCuadrado(float a,float b,float c,float d) {
  78.         if(a==b&b==c&c==d) {
  79.             return true;
  80.         }
  81.         return false;
  82.     }
  83.     public static Boolean esUnRectangulo(float a,float b,float c,float d) {
  84.         if((a==b&c==d)|(a==c&b==d)|(a==d&b==c)) {
  85.             return true;
  86.         }
  87.         return false;
  88.     }
  89.     public static boolean esPositivo(Float numero) {
  90.         if (numero>0) {
  91.             return true;
  92.         }
  93.         return false;
  94.     }
  95.     public static Float menor(float a, float b) {
  96.         if (a!=0&a<b) {
  97.             return a;
  98.         }else{
  99.             return b;
  100.         }
  101.     }
  102.     public static Float mayor(float a, float b) {
  103.         if (a>b) {
  104.             return a;
  105.         }else{
  106.             return b;
  107.         }
  108.     }
  109.     public static void devolverValores(float a, float b, int c) {
  110.         System.out.println("El menor perímetro fue: "+a);
  111.         System.out.println("La menor área fue: "+b);
  112.         System.out.println("Otros polígonos distintos de cuadrado y rectángulo: "+c);
  113.     }
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement