Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tp0nuevo;
- import tp0.Helper;
- import java.util.Random;
- import java.util.Scanner;
- public class Ejercicio6 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int a=0,b=0,c = 0;
- System.out.println("Ejercicio 6 - Tp 0");
- menu(a,b,c);
- }
- @SuppressWarnings("static-access")
- public static void menu(int a,int b, int c) {
- Helper op = new Helper();
- boolean salir= false;
- int opcion;
- while(!salir) {
- System.out.println("1- Ingresar valores");
- System.out.println("2- Generar valores aleatorios");
- System.out.println("3- Fin");
- opcion = op.getInteger("Escriba una opcion");
- switch(opcion){
- case 1:
- Character opcion2;
- do {
- asignar(a,b,c);
- opcion2 = op.getCharacter("Desea ingresar mas valores??(s/n)");
- }while(!opcion2.equals('n'));
- break;
- case 2:
- Character opcion3;
- do {
- a = generarValor();
- b = generarValor();
- c = generarValor();
- System.out.println("Los valores generados son: " + a +" " + b +" "+ c);
- triangulo(a,b,c);
- System.out.println();
- opcion3 = op.getCharacter("Desea generar otros valores??(s/n)");
- }while(!opcion3.equals('n'));
- break;
- case 3:
- System.out.println("Gracias :D");
- salir = true;
- break;
- default:
- System.out.println("Opcion no valida");
- espera();
- }
- }
- }
- public static void asignar(int a, int b, int c) {
- a = ingresarValor();
- if(a>0) {
- b = ingresarValor();
- if (b>0) {
- c = ingresarValor();
- if (c>0) {
- triangulo(a,b,c);
- }
- }
- }
- }
- public static Boolean equilatero(int a, int b, int c) {
- if ((a==b)&&(a==c)) {
- return true;
- }
- return false;
- }
- public static Boolean isoceles(int a, int b, int c) {
- if((a==b)||(b==c)||(a==c)) {
- return true;
- }
- return false;
- }
- public static void triangulo(int a, int b, int c) {
- if(teorema(a,b,c)) {
- if(equilatero(a,b,c)) {
- System.out.println("Es un triangulo Equilatero");
- }else {
- if(isoceles(a,b,c)) {
- System.out.println("Es un triangulo Isoceles");
- }else {
- System.out.println("Es un triangulo Escaleno");
- }
- }
- }else {
- System.out.println("No cumple el Teorema de Desigualdad de Triangulos");
- }
- }
- public static Boolean teorema (int a, int b, int c) {
- if((a+b>c)&&(a+c>b)&&(b+c>a)) {
- System.out.println("Cumple con el teorema");
- return true;
- }
- return false;
- }
- public static Integer ingresarValor() {
- Helper help = new Helper();
- @SuppressWarnings("static-access")
- Integer num = help.getPositiveInt("Ingrese un numero positivo ");
- return num;
- }
- public static Integer generarValor(){
- Random numAl = new Random();
- int num1 = numAl.nextInt(100);
- return num1;
- }
- @SuppressWarnings("resource")
- public static void espera (){ //Este modulo detiene el proceso hasta que el ususario precione "enter"
- Scanner waitForKeypress = new Scanner(System.in);
- System.out.print("Presiona la tecla Enter para continuar....");
- waitForKeypress.nextLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement