import java.io.*; class SumaMatricesComplejas { public static void main(String A[]) { Suma ObjetoSuma; NumeroComplejo A1 = new NumeroComplejo(2, 3); NumeroComplejo A2 = new NumeroComplejo(0, -1); NumeroComplejo A3 = new NumeroComplejo(0, 4); NumeroComplejo A4 = new NumeroComplejo(); NumeroComplejo B1 = new NumeroComplejo(5, 0); NumeroComplejo B2 = new NumeroComplejo(-3, 0); NumeroComplejo B3 = new NumeroComplejo(-3, 2); NumeroComplejo B4 = new NumeroComplejo(1, -8); NumeroComplejo NCA[][] = {{A1,A2}, {A3, A4}}; Matriz MatrizA = new Matriz(NCA); NumeroComplejo NCB[][] = {{B1,B2}, {B3, B4}}; Matriz MatrizB = new Matriz(NCB); ObjetoSuma = new Suma(MatrizA, MatrizB); MatrizA.Suma(NCB); MatrizA.Muestra(ObjetoSuma); } } class Matriz { NumeroComplejo MNC[][] = new NumeroComplejo[2][2]; Suma ObjetoSuma = new Suma(); Matriz(NumeroComplejo MAT[][]) { int r=0, c=0; for(r=0; r<2; r++) for(c=0; c<2; c++) MNC[r][c] = MAT[r][c]; } void Muestra(Suma MNC) { int r=0, c=0; for(r=0; r<2; r++) for(c=0; c<2; c++) System.out.println("R("+r+","+c+")= "+MNC[r][c].Real+ " + j"+MNC[r][c].Imag); } void Suma(NumeroComplejo MAT[][]) { int r=0, c=0; for(r=0; r<2; r++) for(c=0; c<2; c++) { // MNC[r][c].Suma(MAT[r][c].Real, MAT[r][c].Imag); ObjetoSuma = new Suma(MAT[r][c].Real, MAT[r][c].Imag, MNC[r][c]); MNC[r][c].Real = ObjetoSuma.RespR; MNC[r][c].Imag = ObjetoSuma.RespI; } } } class NumeroComplejo { // Campos de la clase float Real; float Imag; Suma ObjetoSuma = new Suma(); // Constructor -NombreMetodo = NobreDeLaClase- NumeroComplejo() { Real = 0; Imag = 0; } NumeroComplejo(float Real, float Imag) { this.Real = Real; this.Imag = Imag; } } class Suma { float R=0, I=0; float RespR=0, RespI=0; NumeroComplejo MatR[][] = new NumeroComplejo[2][2]; Suma(float R, float I, NumeroComplejo NC) { this.R = R; this.I = I; RespR = R + NC.Real; RespI = I + NC.Imag; } Suma() { R = I = RespR = RespI = 0; } Suma(Matriz MA, Matriz MB) { int r=0, c=0; for(r=0; r<2; r++) for(c=0; c<2; c++) { ObjetoSuma = new Suma(MAT[r][c].Real, MAT[r][c].Imag, MNC[r][c]); MatR[r][c].Real = ObjetoSuma.RespR; MatR[r][c].Imag = ObjetoSuma.RespI; } } }