2024-02-28 12:00:20 +01:00
|
|
|
/**
|
2024-02-29 10:44:39 +01:00
|
|
|
* Une classe definissant une matrice carree
|
2024-02-28 12:00:20 +01:00
|
|
|
* @author Luc Dartois
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
|
|
|
public class MatriceCarre{
|
|
|
|
private int n; //taille de la matrice
|
|
|
|
private int[][] m; //La matrice
|
|
|
|
|
|
|
|
/**
|
2024-02-29 10:44:39 +01:00
|
|
|
* Constructeur creant une matrice vide
|
2024-02-28 12:00:20 +01:00
|
|
|
*@param t La taille de la matrice
|
|
|
|
*/
|
|
|
|
public MatriceCarre(int t){
|
|
|
|
this.n=t;
|
|
|
|
this.m=new int[t][t];
|
|
|
|
}
|
|
|
|
/**
|
2024-02-29 10:44:39 +01:00
|
|
|
* Constructeur copiant une matrice donnee dans une nouvelle matrice
|
2024-02-28 12:00:20 +01:00
|
|
|
*@param a La matrice à copier
|
|
|
|
*/
|
|
|
|
public MatriceCarre(MatriceCarre a){
|
|
|
|
this.n=a.n;
|
|
|
|
this.m=new int[this.n][this.n];
|
|
|
|
for(int i=0;i<this.n;i++){
|
|
|
|
for(int j=0;j<this.n;j++){
|
|
|
|
this.m[i][j]=a.m[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
2024-02-29 10:44:39 +01:00
|
|
|
* Methode permettant de definir le coefficient d'une matrice
|
2024-02-28 12:00:20 +01:00
|
|
|
*@param i Le coefficient de ligne
|
|
|
|
*@param j Le coefficient de colonne
|
|
|
|
*@param val La valeur du coefficient
|
|
|
|
*/
|
|
|
|
public void setCoeff(int i,int j,int val){
|
|
|
|
if(i>=this.n||j>=this.n||i<0||j<0){
|
|
|
|
throw new IllegalArgumentException("Erreur : Hors limites de la matrice.");
|
|
|
|
}
|
|
|
|
this.m[i][j]=val;
|
|
|
|
}
|
|
|
|
/**
|
2024-02-29 10:44:39 +01:00
|
|
|
* Methode permettant de recuperer le coefficient d'une matrice
|
2024-02-28 12:00:20 +01:00
|
|
|
*@param i Le coefficient de ligne
|
|
|
|
*@param j Le coefficient de colonne
|
|
|
|
*@return Le coefficient
|
|
|
|
*/
|
|
|
|
public int getCoeff(int i,int j){
|
|
|
|
if(i>=this.n||j>=this.n||i<0||j<0){
|
|
|
|
throw new IllegalArgumentException("Erreur : Hors limites de la matrice.");
|
|
|
|
}
|
|
|
|
return this.m[i][j];
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString(){
|
|
|
|
String s=" ";
|
|
|
|
for(int j=0;j<this.n;j++){
|
|
|
|
s+="| "+j;
|
|
|
|
}
|
|
|
|
s+="|\n";
|
|
|
|
for(int i=0;i<this.n;i++){
|
|
|
|
s+=i+" | ";
|
|
|
|
for(int j=0;j<this.n;j++){
|
|
|
|
s+=this.m[i][j]+"| ";
|
|
|
|
}
|
|
|
|
s+="\n";
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(MatriceCarre a){
|
|
|
|
if(this.n!=a.n)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for(int i=0;i<this.n;i++){
|
|
|
|
for(int j=0;j<this.n;j++){
|
|
|
|
if(this.m[i][j]!=a.m[i][j])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|