Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
- *
- * @Autor: Equipo 4.1
- */
- /* @integrantes: | @Carrera: | @LU:
- Flores ,Cesar Ismael | Lic. en Sistemas | 1782
- Llampa, Ariel Angel Gabriel | Ing. Informatica | 8445
- Machaca, Rodrigo Agustin | Ing. Informatica | 8512
- Perez, Emanuel Ismael | Ing. Informatica | 8393
- Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica | 7286
- Dadas las longitudes de los tres lados de un triángulo, determinar qué clasificación le corresponde
- (Equilátero, Isósceles o Escaleno). Para ello, en primer lugar, se debe determinar si las medidas de los tres
- lados forman un triángulo usando el teorema de la desigualdad del triángulo.
- Teorema de la desigualdad del triángulo: La suma de las longitudes de cualquiera de los dos lados de un
- triángulo es mayor que la longitud del tercer lado.
- Indicaciones:
- Este ejercicio necesita del objeto scanner para ingresar datos por la consola o teclado, se espera que el
- código controle los problemas que normalmente ocurren al operar con la consola o teclado.
- Se espera una correcta modularización entre el código que realiza el ingreso y validación de los datos
- respecto del código que hace lo que se solicita en el ejercicio.
- También necesita del objeto random para generar valores de manera aleatoria.
- El ejercicio debe implementar un mecanismo para seleccionar el ingreso de valores por consola o
- generados aleatoriamente.
- */
- package Intro;
- public class ED_E6 {
- public static void main(String[] args) {
- (new ED_E6()).open();
- }
- public void open() {
- char option;
- do {
- do {
- System.out.println("Estructura de Datos - TP01 Ej. 06");
- System.out.println("(a) Ingreso Manual");
- System.out.println("(b) Ingreso Automatico");
- option = Helper.getChar();
- } while (validateOption(option));
- } while (run(option));
- }
- public boolean triangularInequality(float valueA, float valueB, float valueC) {
- boolean validateA = ((valueB + valueC) > valueA);
- boolean validateB = ((valueA + valueC) > valueB);
- boolean validateC = ((valueB + valueA) > valueC);
- if (validateA & validateB & validateC) {
- return false;
- } else {
- System.out.println("Los valores ingresados no corresponden a un triangulo");
- System.out.println("Intentelo nuevamente");
- return true;
- }
- }
- public String triangularClassification(float valueA, float valueB, float valueC) {
- if (valueA == valueB & valueA == valueC) {
- return "Equilatero";
- } else {
- if (valueA == valueB || valueB == valueC || valueA == valueC) {
- return "Isoceles";
- } else {
- return "Escaleno";
- }
- }
- }
- public void registerManual() {
- float valueA, valueB, valueC;
- do {
- System.out.print("Ingrese el lado (a): ");
- valueA = Helper.getFloatPositive();
- System.out.print("Ingrese el lado (b): ");
- valueB = Helper.getFloatPositive();
- System.out.print("Ingrese el lado (c): ");
- valueC = Helper.getFloatPositive();
- } while (triangularInequality(valueA, valueB, valueC));
- System.out.println("Los valores ingresados corresponden a un triangulo: " + triangularClassification(valueA, valueB, valueC));
- }
- public boolean triangularInequalityAutomatic(float valueA, float valueB, float valueC) {
- boolean validateA = ((valueB + valueC) > valueA);
- boolean validateB = ((valueA + valueC) > valueB);
- boolean validateC = ((valueB + valueA) > valueC);
- if (validateA & validateB & validateC) {
- return false;
- } else {
- System.out.println("Los valores generados no corresponden a un triangulo");
- System.out.println("Se volvera a intentar nuevamente...");
- return true;
- }
- }
- public void registerAutomatic() {
- float valueA, valueB, valueC;
- do {
- valueA = (1 + (100 - 1) * Helper.random.nextFloat());
- valueB = (1 + (100 - 1) * Helper.random.nextFloat());
- valueC = (1 + (100 - 1) * Helper.random.nextFloat());
- System.out.println("Se generaron los siguientes valores: ");
- System.out.println("lado (a): " + valueA);
- System.out.println("lado (b): " + valueB);
- System.out.println("lado (c): " + valueC);
- } while (triangularInequalityAutomatic(valueA, valueB, valueC));
- System.out.println("Los valores ingresados corresponden a un triangulo: " + triangularClassification(valueA, valueB, valueC));
- }
- public boolean run(char option) {
- switch (option) {
- case 'a','A':
- registerManual();
- return false;
- case 'b','B':
- registerAutomatic();
- return false;
- default:
- return true;
- }
- }
- public boolean validateOption(char option) {
- switch (option) {
- case 'a','A':
- return false;
- case 'b','B':
- return false;
- default:
- System.out.println("Opcion no contemplada");
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement