package lezione08; class StudenteSlide18 { String nome; String cognome; int eta; String matricola; EsameSlide14[] carriera; int next; static int counter = 0; StudenteSlide18(String nome, String cognome, int e) { this.nome = nome; this.cognome = cognome; this.eta = e; this.next = 0; this.matricola = StudenteSlide18.generaMatricola(); this.carriera = null; // Andrebbe bene lasciare 'carriera' inizializzato a 'null'? this.carriera = new EsameSlide14[30]; } static String generaMatricola() { String matricola = String.valueOf(StudenteSlide18.counter); // equivalente a 'return StudenteSlide16.counter + ""' ma piu' elegante =) StudenteSlide18.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; } void registraVoto(String materia, int voto) { // SIGNATURE: metodo di nome 'registraVoto' che non ritorna alcun valore e necessita di un valore di tipo 'String' e uno di tipo 'int' in input EsameSlide14 esame = new EsameSlide14(); esame.materia = materia; esame.voto = voto; this.carriera[this.next] = esame; this.next++; } double registraECalcolaMedia(EsameSlide14 esame) { this.registraVoto(esame.materia, esame.voto); return this.calcolaMedia(); } }