import javax.swing.*; class NumComplejos { private int X, Y; public NumComplejos() { X = 0; Y = 0; } public NumComplejos(int x,int y) { X = x; Y = y; } public NumComplejos(NumComplejos n) { X = n.getX(); Y = n.getY(); } public int getX() { return X; } public int getY() { return Y; } public String toString() { return "(" + X + "," + Y + ")"; } public void setX (int x) { X=x; } public void setY (int y) { Y=y; } //operaciones interesantes public NumComplejos sumar(NumComplejos otra) { NumComplejos suma = new NumComplejos(); suma.setX( X + otra.getX() ); suma.setY( Y + otra.getY() ); return suma; } public NumComplejos restar(NumComplejos otra) { NumComplejos resta = new NumComplejos(); resta.setX( X - otra.getX() ); resta.setY( Y - otra.getY() ); return resta; } public NumComplejos multiplicar(NumComplejos otra) { NumComplejos mult = new NumComplejos(); mult.setX( ( X * otra.getX() ) - ( Y * otra.getY() ) ); mult.setY( ( X * otra.getY() ) + ( Y * otra.getX() ) ); return mult; } public NumComplejos dividir(NumComplejos otra) { NumComplejos divi = new NumComplejos(); divi.setX( ( ( X * otra.getX() ) + ( Y * otra.getY() ) ) / ( (otra.getX() )^2 + ( otra.getY() )^2 ) ); divi.setY( ( ( Y * otra.getX() ) - ( X * otra.getY() ) ) / ( (otra.getX() )^2 + ( otra.getY() )^2 ) ); return divi; } } public class Complejos { public static void main(String par[]) { NumComplejos a, b, c; String dato; int x, y, res=0, r=0; do { dato = JOptionPane.showInputDialog("Digite el numero perteneciente al eje X \n del 1er Numero Complejo :"); x = Integer.parseInt(dato); dato = JOptionPane.showInputDialog("Digite el numero perteneciente al eje Y \n del 1er Numero Complejo :"); y = Integer.parseInt(dato); a = new NumComplejos(x, y); dato = JOptionPane.showInputDialog("Digite el numero perteneciente al eje X \n del 2do Numero Complejo :"); x = Integer.parseInt(dato); dato = JOptionPane.showInputDialog("Digite el numero perteneciente al eje Y \n del 2do Numero Complejo :"); y = Integer.parseInt(dato); b = new NumComplejos(x, y); do { dato = JOptionPane.showInputDialog("*********** MENU ************ \n 1. SUMAR \n 2. RESTAR \n 3. MULTIPLICAR \n 4. DIVIDIR \n 5. TERMINAR"); res = Integer.parseInt(dato); switch(res){ case 1: c = b.sumar(a); JOptionPane.showMessageDialog(null, a.toString() + " + " + b.toString() + " = " + c.toString() ); break; case 2: c = b.restar(a); JOptionPane.showMessageDialog(null, a.toString() + " - " + b.toString() + " = " + c.toString() ); break; case 3: c = b.multiplicar(a); JOptionPane.showMessageDialog(null, a.toString() + " x " + b.toString() + " = " + c.toString() ); break; case 4: c = b.dividir(a); JOptionPane.showMessageDialog(null, a.toString() + " / " + b.toString() + " = " + c.toString() ); break; case 5: break; default: JOptionPane.showMessageDialog(null, "Opcion invalida!"); } }while(res!=5); dato = JOptionPane.showInputDialog("1. dato nuevo \n 2. salir"); res = Integer.parseInt(dato); }while(res!=2); System.exit(0); } }