package lezione08; class StudenteSlide17 { String nome; String cognome; int eta; String matricola; EsameSlide14[] carriera; int next; static int counter = 0; // Campo comune a TUTTI gli oggetti: tutti gli oggetti "vedono" lo stesso valore (non ne hanno una propria copia privata) StudenteSlide17(String nome, String cognome, int e) { this.nome = nome; this.cognome = cognome; this.eta = e; this.next = 0; this.matricola = StudenteSlide17.generaMatricola(); } static String generaMatricola() { // Metodo comune a TUTTI gli oggetti String matricola = String.valueOf(StudenteSlide17.counter); // equivalente a 'return StudenteSlide16.counter + ""' ma piu' elegante =) StudenteSlide17.counter++; return matricola; // NOTA: NON 'this.matricola' } double calcolaMedia(){ double somma = this.sommaVoti(this.carriera); return somma / this.next; } double sommaVoti(EsameSlide14[] carriera) { double somma = 0; for (int i = 0; i < next; i++) { somma += carriera[i].voto; } return somma; } int registraVoto(String materia, int voto) { EsameSlide14 esame = new EsameSlide14(); esame.materia = materia; esame.voto = voto; this.carriera[this.next] = esame; this.next++; return next; } double registraECalcolaMedia(EsameSlide14 esame) { this.registraVoto(esame.materia, esame.voto); return this.calcolaMedia(); } }