You are on page 1of 9

Luis Jos Alarcn Aneiva

Comentario: En esta tarea creo que logre ver


resultados en el progreso con mi lgica en matrices,
sobre todo en la ultimo problema en el cual estaba en
un nivel ms complicado que el resto de los ejercicios.
Terminado al 100%
import java.util.*;
/**
*
* @author Lab03-14
*/
public class Matriz {
private int maxFil;
private int maxCol;
private int cantFil;
private int cantCol;
private int elem[][];

public Matriz(int n , int m){


this.maxFil = n;
this.maxCol = m;
this.cantCol = this.cantFil = 0;
this.elem = new int [n][m];
}
public void fijarDimension(int n , int m){
this.cantFil = n;
this.cantCol= m;
}
public void setElem( int i, int j ,int x){
this.elem[i][j] = x;
}
public void mostrar(){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
System.out.print(this.elem[i][j] + "\t");
j = j + 1;
}
System.out.println();
i = i + 1;
}
}
public int frecuencia( int var){
int i = 0, p = 0;
while( i < this.cantFil){
int j = 0;

while( j < this.cantCol){


if(var == this.elem[i][j]) p = p + 1;
j = j + 1;
}
i = i + 1;
}
return p;
}
public boolean iguales(){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
if(this.elem[0][0] != this.elem[i][j]) return false;
j = j + 1;
}
i = i + 1;
}
return true;
}
public boolean diferentes(){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
if(this.frecuencia(this.elem[i][j]) >1) return false;
j = j + 1;
}
i = i + 1;
}
return true;
}
public int sumaFila(int var){
int j = 0, p = 0;
while( j < this.cantCol){
p = p + this.elem[var][j];
j = j + 1;
}
return p;
}
public int sumaCol(int var){
int i = 0, cont = 0;
while( i < this.cantFil){
cont = cont + this.elem[i][var];
i = i + 1;
}
return cont;
}
public int suma(){
int i = 0, cont = 0;
while( i < this.cantFil){
int j = 0;

while( j < this.cantCol){


cont = cont + this.elem[i][j];
j = j + 1;
}
i = i + 1;
}
return cont;
}
public int menorFila(int i){
int j = 0, p = this.elem[i][0];
while( j < this.cantCol){
if(p > this.elem[i][j]) p = this.elem[i][j];
j = j + 1;
}
return p;
}
public int menorCol(int var){
int i = 0, p = this.elem[0][var];
while( i < this.cantCol){
if(p > this.elem[i][var]) p = this.elem[i][var];
i = i + 1;
}
return p;
}
public int menor(){
int i = 0, men = this.elem[0][0];
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
if(men > this.elem[i][j]) men = this.elem[i][j];
j = j + 1;
}
i = i + 1;
}
return men;
}
public boolean ordenAscFila(int var){
int j = 1, p = this.elem[var][0];
while( j < this.cantCol){
if(p > this.elem[var][j]) return false;
p = this.elem[var][j];
j = j + 1;
}
return true;
}
public boolean ordenAsc(){
int i = 0, varPiv = this.elem[0][0];
while( i < this.cantFil){

int j = 0;
while( j < this.cantCol){
if(varPiv > this.elem[i][j]) return false;
varPiv = this.elem[i][j];
j = j + 1;
}
i = i + 1;
}
return true;
}
public void intercambiar(int i1, int i2){
int j =0 , p = 0;
while( j < this.cantCol){
p= this.elem[i1][j];
this.elem[i1][j] = this.elem[i2][j];
this.elem[i2][j] = p;
j = j + 1;
}
}
public void generarSec(int a , int k){
int i = 0, cont = a;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
this.elem[i][j] = cont;
cont = cont + k;
j = j + 1;
}
i = i + 1;
}

}
public int aleatorio(int a , int b){
int p = Math.abs(a-b), men = 0;
if(a < b) men = a;
else men = b;
return (int)(p* Math.random())+ men;
}

public int sumaDiagP(){


int i = 0 , sum = 0;
while(i < this.cantFil && i < this.cantCol){
sum = sum + this.elem[i][i];
i = i + 1;
}
return sum;
}
public int sumaDiagS(){
int i = 0 ,j = this.cantCol, sum = 0;
while(i < this.cantFil && j >= 0){
sum = sum + this.elem[i][j];

i = i + 1;
j = j - 1;
}
return sum;
}
public int menorDiagP(){
int i = 0 , menor = this.elem[0][0];
while(i < this.cantFil && i < this.cantCol){
if( menor > this.elem[i][i]) menor = this.elem[i][i];
i = i + 1;
}
return menor;
}
public int menorDiagS(){
int i = 0 ,j = this.cantCol, menor = this.elem[0][this.cantCol];;
while(i < this.cantFil && j >= 0){
if( menor > this.elem[i][j]) menor = this.elem[i][i];
i = i + 1;
j = j - 1;
}
return menor;
}
public boolean igualesDiagP(){
int i = 0 , igual = this.elem[0][0];
while(i < this.cantFil && i < this.cantCol){
if( igual != this.elem[i][i]) return false;
i = i + 1;
}
return true;
}
public boolean matrizIdentidad(){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
if(i == j){
if(this.elem[i][j] != 1) return false;
}
else{
if(this.elem[i][j] != 0) return false;
}
j = j + 1;
}
i = i + 1;
}
return true;
}
public void menoresCols( ArrayList L1 ){
int j = 0;
while( j < this.cantCol){
int i = 0 , men= this.elem[i][j];
while( i < this.cantFil){
if(men > this.elem[i][j])men = this.elem[i][j];
i = i + 1;
}
L1.add(men);
j = j + 1;

}
}
public void menoresFilas( ArrayList L1 ){
int i = 0;
while( i < this.cantFil){
int j = 0 , men= this.elem[i][j];
while( i < this.cantCol){
if(men > this.elem[i][j])men = this.elem[i][j];
j = j + 1;
}
L1.add(men);
i = i + 1;
}
}
public void DiagonalPrincipal( ArrayList L1){
int i = 0 ;
while(i < this.cantFil && i < this.cantCol){
L1.add(this.elem[i][i]);
i = i + 1;
}
}
public void DiagonalSecundaria( ArrayList L1){
int i = 0 ,j = this.cantCol;
while(i < this.cantFil && j >= 0){
L1.add(this.elem[i][j]);
i = i + 1;
j = j - 1;
}
}
public void sumaCols( ArrayList L1 ){
int j = 0;
while( j < this.cantCol){
int i = 0 , sum = 0;
while( i < this.cantFil){
sum = sum + this.elem[i][j];
i = i + 1;
}
L1.add(sum);
j = j + 1;
}
}
public void sumaFilas( ArrayList L1 ){
int i = 0;
while( i < this.cantFil){
int j = 0 , sum = 0;
while( i < this.cantCol){
sum = sum + this.elem[i][j];
j = j + 1;
}
L1.add(sum);
i = i + 1;
}
}
public void generarRandom( int a , int b){
int i = 0;
while( i < this.cantFil){

int j = 0;
while( j < this.cantCol){
this.elem[i][j] = aleatorio(a,b);
j = j + 1;
}
i = i + 1;
}
}
public void generarRandomDif( int a , int b){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
int alea= 0;
alea = aleatorio(a,b);
while(this.frecuencia(alea)> 0){
alea = aleatorio(a,b);
}
this.elem[i][j] = alea;
j = j + 1;
}
i = i + 1;
}
}
public void generarRandomFila( int a , int b){
int j = 0;
while( j < this.cantCol){
int i = 0, alea = aleatorio(a,b) ;
while( j < this.cantFil){
this.elem[i][j] = alea;
i = i + 1;
}
j = j + 1;
}
}
public void generarSecuencia( int a , int k){
int i = 0, Secu = a;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
this.elem[i][j] = Secu;
Secu = Secu + k;
j = j + 1;
}
i = i + 1;
}
}
public void generarFilas(){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
this.elem[i][j] = i;
j = j + 1;
}
i = i + 1;
}

}
public void generarCols(){
int j = 0;
while( j < this.cantCol){
int i = 0;
while( j < this.cantFil){
this.elem[i][j] = j;
i = i + 1;
}
j = j + 1;
}
}
public boolean mismosElem1( Matriz m2){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
if(m2.frecuencia(this.elem[i][j]) == 0) return false;
j = j + 1;
}
i = i + 1;
}
return true;
}
public boolean mismosElem( Matriz m2){
return (this.mismosElem1(m2)&& m2.mismosElem1(this));
}
public boolean interseccion( Matriz m2){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
if(m2.frecuencia(this.elem[i][j])> 0) return true;
j = j + 1;
}
i = i + 1;
}
return false;
}
public boolean exclusion( Matriz m2){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
if(m2.frecuencia(this.elem[i][j])> 0) return false;
j = j + 1;
}
i = i + 1;
}
return true;
}
public boolean transpuesta( Matriz m2){
int i = 0;
while( i < this.cantFil){
int j = 0;
while( j < this.cantCol){
this.elem[i][j] = m2.elem[j][i];

j = j + 1;
}
i = i + 1;
}
return true;
}
public boolean subMatriz( Matriz m2){
int i = 0, m1Elem= this.cantCol* this.cantFil ;
while( i < m2.cantFil){
int j = 0;
while( j < m2.cantCol){
if(m2.elem[i][j] == this.elem[0][0]){
int m = i, i2 = 0, acum= 0 ;
while( m < m2.cantFil){
int n = j, j2 = 0;
while( n < m2.cantCol){
if(this.elem[i2][j2] == m2.elem[m][n]) acum=
acum + 1;
n = n + 1;
j2 = j2 + 1;
}
m = m + 1;
i2 = i2 + 1;
}
if( acum == m1Elem) return true;
}
j = j + 1;
}
i = i + 1;
}
return false;
}

You might also like