package soluzione11092017; import java.util.ArrayList; public class SoluzioneTestoBMatrice { private String nome; private ArrayList> mat; private int nrighe; private int ncolonne; public SoluzioneTestoBMatrice(String name) { this.nome = name; this.mat = new ArrayList>(); this.nrighe = 0; this.ncolonne = 0; } public String getNome() { return this.nome; } public int getNRighe() { return this.nrighe; } public int getNColonne() { return this.ncolonne; } public void aggiungi(String line) { ArrayList riga = new ArrayList(); String[] l = line.split(","); for (int i = 0; i < l.length; i++) { riga.add(Integer.parseInt(l[i].trim())); } mat.add(riga); nrighe++; ncolonne = l.length; } public int getElemento(int riga, int colonna) { ArrayList row; row = mat.get(riga); return row.get(colonna); } public String toString() { StringBuffer sb = new StringBuffer(nome + "\n"); for (int i = 0; i < nrighe; i++) { for (int j = 0; j < ncolonne; j++) { sb.append(mat.get(i).get(j) + " "); } sb.append("\n"); } sb.append("\n"); return sb.toString(); } public boolean matriceColonna() { return this.ncolonne == 1; } public int somma() { int somma = 0; for (int i = 0; i < nrighe; i++) { for (int j = 0; j < ncolonne; j++) { somma += mat.get(i).get(j); } } return somma; } public boolean quadrata() { return this.nrighe == this.ncolonne; } public boolean triangolareInferiore() { boolean trianginf = false; if (quadrata() == true) { for (int i = 0; i < nrighe; i++) { for (int j = 0; j < ncolonne; j++) { if (j > i && mat.get(i).get(j) == 0) { trianginf = true; } } } } return trianginf; } public boolean nonHaElementiDuplicati() { boolean noduplicati = true; for (int i = 0; i < nrighe; i++) { for (int j = 1; j < ncolonne; j++) { for (int k = 0; k < j; k++) { if (mat.get(i).get(j) == mat.get(i).get(k)) { noduplicati = false; break; } } } } return noduplicati; } }