package complejo;
import java.util.*;
public class Aplicacion{ Scanner teclado = new Scanner(System.in);
public static int Menu(){ Scanner teclado = new Scanner(System.in);
int opcion;
System.out.println();
System.out.println("calculadora de numeros complejos"); System.out.println();
System.out.println("1)SUMAR"); System.out.println("2)RESTAR"); System.out.println("3)MULTIPLICAR"); System.out.println("4)DIVIDIR"); System.out.println("5)MODULO"); System.out.println("6)ARGUMENTO"); System.out.println("7)SABER SI SON IGUALES O NO"); System.out.println("8)SABER SI SON SIMILARES O NO"); System.out.println("9)CALCULAR EL COMPLEJO CONJUGADO"); System.out.println("10)PARTE REAL DE UN COMPLEJO"); System.out.println("11)PARTE IMAGINARIA DE UN COMPLEJO"); System.out.println("12)POTENCIA DE UN COMPLEJO"); System.out.println("13)INVERSO MULTIPLICATIVO"); System.out.println("14)INVERSO ADITIVO"); System.out.println("15)MOSTRAR COMPLEJO POR PANTALLA"); System.out.println("16)PASAR A POLAR"); System.out.println("17)PASAR A BINOMICA"); System.out.println("18)SALIR"); System.out.println();
System.out.print(" OPCION: "); opcion = teclado.nextInt();
return opcion;
}
public static void main(String[] args) { Scanner teclado = new Scanner(System.in);
Complejo calculadora,c1,c2,resultado;
Process p;
calculadora = new Complejo();
double real, imag;
int opcion;
double solucion;
boolean iguales;
int exp;
String polar;
do{ opcion = Menu();
switch(opcion){ case 1:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
System.out.print("Escribe el segundo real: "); real = teclado.nextDouble();
System.out.print("Escribe el segundo imaginario: "); imag = teclado.nextDouble();
c2=new Complejo(real, imag);
resultado=Complejo.suma(c1, c2);
System.out.println("Suma "+resultado);
break;
case 2:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
System.out.print("Escribe el segundo real: "); real = teclado.nextDouble();
System.out.print("Escribe el segundo imaginario: "); imag = teclado.nextDouble();
c2=new Complejo(real, imag);
resultado=Complejo.resta(c1, c2);
System.out.println("rest "+resultado); break;
case 3:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
System.out.print("Escribe el segundo real: "); real = teclado.nextDouble();
System.out.print("Escribe el segundo imaginario: "); imag = teclado.nextDouble();
c2=new Complejo(real, imag);
resultado=Complejo.producto(c1, c2);
System.out.println("Producto "+resultado); break;
case 4:
try{ System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
System.out.print("Escribe el segundo real: "); real = teclado.nextDouble();
System.out.print("Escribe el segundo imaginario: "); imag = teclado.nextDouble();
c2=new Complejo(real, imag);
resultado=Complejo.cociente(c1, c2);
System.out.println("Division "+resultado); }catch(ExcepcionDivideCero ex){ System.out.println("Al calcular el cociente se ha producido una excepción\n " +ex.getClass()+ " con el mensaje "+ ex.getMessage());
}
break;
case 5:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
solucion=c1.modulo();
System.out.println(solucion);
break;
case 6:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
solucion=c1.argumento();
System.out.println(solucion);
break;
case 7:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
System.out.print("Escribe el segundo real: "); real = teclado.nextDouble();
System.out.print("Escribe el segundo imaginario: "); imag = teclado.nextDouble();
c2=new Complejo(real, imag);
iguales=Complejo.complejoIguales(c1, c2);
System.out.println("¿Son iguales? "+iguales); break;
case 8:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
System.out.print("Escribe el segundo real: "); real = teclado.nextDouble();
System.out.print("Escribe el segundo imaginario: "); imag = teclado.nextDouble();
c2=new Complejo(real, imag);
iguales=Complejo.complejoSimilares(c1, c2);
System.out.println("¿Son similares? "+iguales); break;
case 9:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
resultado=c1.conjugado(c1);
System.out.println("Conjugado:"+resultado); break;
case 10:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
solucion=c1.mostrarParteReal(c1);
System.out.println("La parte real es:"+solucion); break;
case 11:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
solucion=c1.mostrarParteImag(c1);
System.out.println("La parte imaginaria es:"+solucion); break;
case 12:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
System.out.print("Escribe el exponente: "); exp = teclado.nextInt();
resultado=Complejo.potencia(c1, exp);
System.out.println("Potencia "+resultado); break;
case 13:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
resultado=c1.inversoMultiplicativo(c1);
System.out.println("El inverso multiplicativo es:"+resultado); break;
case 14:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
resultado=c1.inversoAditivo(c1);
System.out.println("El inverso aditivo es:"+resultado); break;
case 15:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
resultado=c1.mostrarComplejo(c1);
System.out.println("Complejo:"+resultado); break;
case 16:
System.out.print("Escribe el primer real: "); real = teclado.nextDouble();
System.out.print("Escribe el primer imaginario: "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
polar=c1.binomicaPolar(c1);
System.out.println("Forma polar:"+polar); break;
case 17:
System.out.print("Escribe el modulo: "); real = teclado.nextDouble();
System.out.print("Escribe el argumento(grados): "); imag = teclado.nextDouble();
c1=new Complejo(real, imag);
resultado=c1.polarBinomica(c1);
System.out.println("Forma binomica:"+resultado); break;
case 18:
System.out.println("Adiós");
default:
break;
}
}while(opcion!=18);
}
}