Suma:
/**
* Write a description of class Suma here.
*
* @author (Esteban Montes)
* @version (a version number or a date)
*/
public class Suma
{
private int[][] resultado;
public Suma(int iTam, int jTam)
{
this.setResultado(new int[iTam][jTam]);
}
public int[][] getResultado()
{
return resultado;
}
private void setResultado(int[][] resultado)
{
if(resultado != null){
this.resultado = resultado;
}
}
public int[][] mSuma(int[][] matriz1, int[][] matriz2)
{
for(int i=0; i<matriz1.length; i++){
for(int j=0; j<matriz1[0].length; j++){
resultado[i][j] = matriz1[i][j] + matriz2[i][j];
}
}
return this.getResultado();
}
public void print()
{
MostrarMatriz matriz = new MostrarMatriz();
matriz.print(this.getResultado());
}
}
/**
* Write a description of class Resta here.
*
* @author (Esteban Montes)
* @version (a version number or a date)
*/
public class Resta
{
private int[][] resultado;
public Resta(int iTam, int jTam)
{
this.setResultado(new int[iTam][jTam]);
}
public int[][] getResultado()
{
return resultado;
}
private void setResultado(int[][] resultado)
{
if(resultado != null){
this.resultado = resultado;
}
}
public int[][] mResta(int[][] matriz1, int[][] matriz2)
{
for(int i=0; i<matriz1.length; i++){
for(int j=0; j<matriz1[0].length; j++){
resultado[i][j] = matriz1[i][j] - matriz2[i][j];
}
}
return this.getResultado();
}
public void print()
{
MostrarMatriz matriz = new MostrarMatriz();
matriz.print(this.getResultado());
}
}
/**
* Write a description of class Producto here.
*
* @author (Esteban Montes)
* @version (a version number or a date)
*/
public class Producto
{
private int[][] resultado;
public Producto(int iTam, int jTam)
{
this.setResultado(new int[iTam][jTam]);
}
public int[][] getResultado()
{
return resultado;
}
private void setResultado(int[][] resultado)
{
if(resultado != null){
this.resultado = resultado;
}
}
public int[][] mProducto(int[][] matriz1, int[][] matriz2)
{
if(matriz1.length == matriz2[0].length){
int aux= 0;
for(int i=0; i<matriz1.length; i++){
for(int j=0; j<matriz2.length; j++){
aux=0;
for(int k=0; k<matriz2.length; k++){
aux+= matriz1[i][k] * matriz2[k][j];
}
resultado[i][j] = aux;
}
}
return resultado;
}
return null;
}
public void print()
{
MostrarMatriz matriz = new MostrarMatriz();
matriz.print(this.getResultado());
}
}
/**
* Write a description of class Traspuesta here.
*
* @author (Esteban Montes)
* @version (a version number or a date)
*/
public class Traspuesta
{
private int[][] resultado;
public Traspuesta(int iTam, int jTam)
{
this.setResultado(new int[iTam][jTam]);
}
public int[][] getResultado()
{
return resultado;
}
private void setResultado(int[][] resultado)
{
if(resultado != null){
this.resultado = resultado;
}
}
public int[][] mTrasposicion(int[][] matriz)
{
for(int i=0; i<matriz.length; i++)
{
for(int j=0; j<matriz[0].length; j++)
{
resultado[i][j] = matriz[j][i];
}
}
return this.getResultado();
}
public void print()
{
MostrarMatriz matriz = new MostrarMatriz();
matriz.print(this.getResultado());
}
}
/**
* Write a description of class ProductoEscalar here.
*
* @author (Esteban Montes)
* @version (a version number or a date)
*/
public class ProductoEscalar
{
private int[][] resultado;
public ProductoEscalar(int iTam, int jTam)
{
this.setResultado(new int[iTam][jTam]);
}
public int[][] getResultado()
{
return resultado;
}
private void setResultado(int[][] resultado)
{
if(resultado != null){
this.resultado = resultado;
}
}
public int[][] escalarProducto(int[][] matriz1, int escalar)
{
for(int i=0; i<matriz1.length; i++){
for(int j=0; j<matriz1[0].length; j++){
resultado[i][j] = matriz1[i][j] * escalar;
}
}
return this.getResultado();
}
public void print()
{
MostrarMatriz matriz = new MostrarMatriz();
matriz.print(this.getResultado());
}
}
/**
* Write a description of class Potencia here.
*
* @author (Esteban Montes)
* @version (a version number or a date)
*/
public class Potencia
{
private int[][] resultado;
public int[][] getResultado()
{
return resultado;
}
private void setResultado(int[][] resultado)
{
if(resultado != null)
this.resultado = resultado;
}
public int[][] mPotencia(int[][] matriz, int n)
{
Producto producto = new Producto(matriz.length, matriz[0].length);
this.setResultado(matriz);
for(int i=1; i<=n; i++)
this.setResultado(producto.mProducto(matriz, this.getResultado()));
return resultado;
}
public void print()
{
MostrarMatriz mostrarMatriz = new MostrarMatriz();
mostrarMatriz.print(this.getResultado());
}
}
/**
* Write a description of class MostrarMatriz here.
*
* @author (Esteban Montes)
* @version (a version number or a date)
*/
public class MostrarMatriz
{
public void print(int[][] matriz)
{
for(int i=0; i<matriz.length; i++){
for(int j=0; j<matriz[0].length; j++){
System.out.print(""+matriz[i][j] + "\t");
}
System.out.println("");
}
}
}
Saludos