Advertisement
MOISES_QUISPE_ROJAS

Estructura Datos 2021 - TP00 P06

Aug 27th, 2021 (edited)
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.57 KB | None | 0 0
  1. /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
  2.  *
  3.  * @Autor: Equipo 4.1
  4.  */
  5.  /*      @integrantes:                  |    @Carrera:             |   @LU:
  6.    Flores ,Cesar Ismael                 | Lic. en Sistemas         | 1782
  7.    Llampa, Ariel Angel Gabriel          | Ing. Informatica         | 8445
  8.    Machaca, Rodrigo Agustin             | Ing. Informatica         | 8512
  9.    Perez, Emanuel Ismael                | Ing. Informatica         | 8393
  10.    Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica         | 7286
  11.  
  12. Dadas las longitudes de los tres lados de un triángulo, determinar qué clasificación le corresponde
  13. (Equilátero, Isósceles o Escaleno). Para ello, en primer lugar, se debe determinar si las medidas de los tres
  14. lados forman un triángulo usando el teorema de la desigualdad del triángulo.
  15. Teorema de la desigualdad del triángulo: La suma de las longitudes de cualquiera de los dos lados de un
  16. triángulo es mayor que la longitud del tercer lado.
  17.  
  18. Indicaciones:
  19. Este ejercicio necesita del objeto scanner para ingresar datos por la consola o teclado, se espera que el
  20. código controle los problemas que normalmente ocurren al operar con la consola o teclado.
  21. Se espera una correcta modularización entre el código que realiza el ingreso y validación de los datos
  22. respecto del código que hace lo que se solicita en el ejercicio.
  23. También necesita del objeto random para generar valores de manera aleatoria.
  24. El ejercicio debe implementar un mecanismo para seleccionar el ingreso de valores por consola o
  25. generados aleatoriamente.
  26.  */
  27. package Intro;
  28.  
  29. public class ED_E6 {
  30.     public static void main(String[] args) {
  31.         (new ED_E6()).open();
  32.     }
  33.  
  34.     public void open() {
  35.         char option;
  36.         do {
  37.             do {
  38.                 System.out.println("Estructura de Datos - TP01 Ej. 06");
  39.                 System.out.println("(a) Ingreso Manual");
  40.                 System.out.println("(b) Ingreso Automatico");
  41.                 option = Helper.getChar();
  42.             } while (validateOption(option));
  43.         } while (run(option));
  44.     }
  45.  
  46.     public boolean triangularInequality(float valueA, float valueB, float valueC) {
  47.         boolean validateA = ((valueB + valueC) > valueA);
  48.         boolean validateB = ((valueA + valueC) > valueB);
  49.         boolean validateC = ((valueB + valueA) > valueC);
  50.         if (validateA & validateB & validateC) {
  51.             return false;
  52.         } else {
  53.             System.out.println("Los valores ingresados no corresponden a un triangulo");
  54.             System.out.println("Intentelo nuevamente");
  55.             return true;
  56.         }
  57.     }
  58.  
  59.     public String triangularClassification(float valueA, float valueB, float valueC) {
  60.         if (valueA == valueB & valueA == valueC) {
  61.             return "Equilatero";
  62.         } else {
  63.             if (valueA == valueB || valueB == valueC || valueA == valueC) {
  64.                 return "Isoceles";
  65.             } else {
  66.                 return "Escaleno";
  67.             }
  68.         }
  69.     }
  70.  
  71.     public void registerManual() {
  72.         float valueA, valueB, valueC;
  73.         do {
  74.             System.out.print("Ingrese el lado (a): ");
  75.             valueA = Helper.getFloatPositive();
  76.             System.out.print("Ingrese el lado (b): ");
  77.             valueB = Helper.getFloatPositive();
  78.             System.out.print("Ingrese el lado (c): ");
  79.             valueC = Helper.getFloatPositive();
  80.         } while (triangularInequality(valueA, valueB, valueC));
  81.         System.out.println("Los valores ingresados corresponden a un triangulo: " + triangularClassification(valueA, valueB, valueC));
  82.     }
  83.  
  84.     public boolean triangularInequalityAutomatic(float valueA, float valueB, float valueC) {
  85.         boolean validateA = ((valueB + valueC) > valueA);
  86.         boolean validateB = ((valueA + valueC) > valueB);
  87.         boolean validateC = ((valueB + valueA) > valueC);
  88.         if (validateA & validateB & validateC) {
  89.             return false;
  90.         } else {
  91.             System.out.println("Los valores generados no corresponden a un triangulo");
  92.             System.out.println("Se volvera a intentar nuevamente...");
  93.             return true;
  94.         }
  95.     }
  96.  
  97.     public void registerAutomatic() {
  98.         float valueA, valueB, valueC;
  99.         do {
  100.             valueA = (1 + (100 - 1) * Helper.random.nextFloat());
  101.             valueB = (1 + (100 - 1) * Helper.random.nextFloat());
  102.             valueC = (1 + (100 - 1) * Helper.random.nextFloat());
  103.             System.out.println("Se generaron los siguientes valores: ");
  104.             System.out.println("lado (a): " + valueA);
  105.             System.out.println("lado (b): " + valueB);
  106.             System.out.println("lado (c): " + valueC);
  107.         } while (triangularInequalityAutomatic(valueA, valueB, valueC));
  108.         System.out.println("Los valores ingresados corresponden a un triangulo: " + triangularClassification(valueA, valueB, valueC));
  109.     }
  110.  
  111.     public boolean run(char option) {
  112.         switch (option) {
  113.             case 'a','A':
  114.                 registerManual();
  115.                 return false;
  116.             case 'b','B':
  117.                 registerAutomatic();
  118.                 return false;
  119.             default:
  120.                 return true;
  121.         }
  122.     }
  123.  
  124.     public boolean validateOption(char option) {
  125.         switch (option) {
  126.             case 'a','A':
  127.                 return false;
  128.             case 'b','B':
  129.                 return false;
  130.             default:
  131.                 System.out.println("Opcion no contemplada");
  132.                 return true;
  133.         }
  134.     }
  135.  
  136. }
  137.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement