Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tp0nuevo;
- import tp0.Helper;
- public class Tp0ejercicio2 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("Ejercicio 2 Tp0");
- int op=0;
- int n = ingresarCantidad();
- while (op != 3&op != 2 &op != 1) {
- op = opcion();
- switch (op) {
- case 1:
- evaluarAngulo(n,true);
- System.out.println("Finalizando programa... Adiós!");
- break;
- case 2:
- evaluarAngulo(n,false);
- System.out.println("Finalizando programa... Adiós!");
- break;
- case 3:
- System.out.println("Programa Terminado");
- break;
- default:
- System.out.println("No es una opción correcta ");
- break;
- }
- }
- }
- @SuppressWarnings("static-access")
- public static Integer ingresarCantidad() {
- Helper numero = new Helper();
- int n = numero.getPositiveInt("Ingrese la cantidad de ángulos que desea generar");
- return n;
- }
- @SuppressWarnings("static-access")
- public static int opcion() {
- Helper numero = new Helper();
- System.out.println("Desea generar ángulos aleatoriamente o ingresar manualmente?");
- System.out.println("1. Aleatorio");
- System.out.println("2. Manual");
- System.out.println("3. Salir");
- Integer opcion = numero.getInteger("Ingrese una opción","Ingrese un número ");
- return opcion;
- }
- public static Integer aleatorio() {
- Integer angulo = (int) (Math.random()*100);
- System.out.println("Su ángulo generado aleatoriamente es = "+angulo);
- return angulo;
- }
- @SuppressWarnings("static-access")
- public static Integer manual() {
- Helper entero = new Helper();
- Integer angulo = entero.getInteger("Ingrese el valor del ángulo (debe ser un número entero)");
- return angulo;
- }
- public static boolean esAgudo(int angulo) {
- if (angulo>0&angulo<90) return true;
- return false;
- }
- public static boolean esObtuso(int angulo) {
- if (angulo>90&&angulo<180) return true;
- return false;
- }
- public static boolean esConvexo(int angulo) {
- if (angulo>180) return true;
- return false;
- }
- public static void evaluarAngulo(int n, boolean b) {
- int cont1 = 0, cont2 = 0, angulo = 0;
- for (int i = 0; i<n; i++) {
- if (b){
- angulo = aleatorio();
- }else{
- angulo = manual()}
- if (angulo==360) {
- System.out.println("Es un giro");
- }else if (angulo>360) {
- System.out.println("Es mas de un giro!");
- }else {
- if (esAgudo (angulo)) {
- int complementario = 90-angulo;
- System.out.println("Es un ángulo agudo ");
- System.out.println("Ángulo complementario = "+complementario);
- }else if (esObtuso(angulo)) {
- cont1++;
- int suplementario = 180-angulo;
- System.out.println("Es un ángulo obtuso ");
- System.out.println("Ángulo suplementario = "+suplementario);
- }else if (esConvexo(angulo)){
- cont2++;
- System.out.println("Es otro ángulo");
- }else if (angulo==90) {
- System.out.println("Es un ángulo recto ");
- }else if (angulo==180) {
- System.out.println("Es un ángulo llano ");
- }
- }
- }
- System.out.println("obtusos "+cont1);
- System.out.println("convexos "+cont2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement