Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main6 {
- public static void main(String[] args){
- int a = 0,b = 0,c = 0;
- boolean repeat = true;
- while(repeat) {
- switch(menu()) {
- case 1:
- //Ingreso por teclado
- a = Helper.getPositiveInt("Ingrese un número a: ");
- b = Helper.getPositiveInt("Ingrese un número b: ");
- c = Helper.getPositiveInt("Ingrese un número c: ");
- break;
- case 2:
- //Generación de numeros aleatorios
- a = Helper.randomInt(1,100);
- b = Helper.randomInt(1,100);
- c = Helper.randomInt(1,100);
- System.out.println("Números generados: a="+ a + " b=" + b + " c=" + c);
- pressEnterKeyToContinue();
- break;
- case 3:
- //Código que hace lo que se solicita en el ejercicio.
- setTriangle(a,b,c);
- break;
- case 4:
- System.out.println("Programa finalizado");
- repeat = false;
- break;
- }
- }
- }
- public static int menu() {
- int option;
- do{
- System.out.println(System.lineSeparator().repeat(50));
- System.out.println("----------------------------------");
- System.out.println(" Opciones disponibles");
- System.out.println("----------------------------------");
- System.out.println(" 1. Ingresar datos");
- System.out.println(" 2. Generar datos aleatorios");
- System.out.println(" 3. Determinar triángulo");
- System.out.println("\n 4. Salir");
- System.out.println("----------------------------------");
- option = Helper.getInt("\nIngrese una opción: ");
- if(option > 4 || option < 1) {
- System.out.println("No hay opción para lo ingresado");
- }
- }while(option > 4 && option < 1);
- return option;
- }
- public static void pressEnterKeyToContinue()
- {
- System.out.println("\nPulse una tecla para continuar...");
- Helper.scanner.nextLine();
- }
- public static void setTriangle(int a, int b, int c) {
- if(a != 0 && b != 0 && c != 0) {
- try {
- Triangle triangle = new Triangle(a,b,c);
- System.out.println(triangle.toString());
- } catch (TriangleException e) {
- System.out.println("a="+ a + " b=" + b + " c=" + c);
- System.out.println("No cumple el Teorema de la desigualdad del triángulo");
- }
- }else {
- System.out.println("Primero cargue valores");
- }
- pressEnterKeyToContinue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement