AnagraficaStudenti.java
Created with JBuilder |
class AnagraficaStudenti {
// Attributi
private Studente[] studente;
private int numeroStudenti;
private int posizioneCorrente;
// Costruttori
public AnagraficaStudenti(int numeroMaxStudenti)
{
studente = new Studente[numeroMaxStudenti];
numeroStudenti = 0;
posizioneCorrente = 0;
}
// Metodo per l'aggiunta di uno studente
// Ritorna false se non è possibile aggiungere
// lo studente e ritorna true altrimenti
public boolean aggiungi(Studente s)
{
if (numeroStudenti < studente.length) {
studente[numeroStudenti] = s;
++numeroStudenti;
return true;
} else {
return false;
}
}
// Metodo per la ricerca di uno studente per matricola
// Ritorna null se lo studente non è presente
// nell'elenco; altrimenti ritorna lo studente trovato
public Studente cercaPerMatricola(int matricolaCercata)
{
for (int i = 0; i < numeroStudenti; ++i) {
if (studente[i].restituisciMatricola() == matricolaCercata) {
return studente[i];
}
}
return null;
}
// Metodo per la ricerca di studenti di un dato corso
public AnagraficaStudenti cercaStudentiDelCorso(String corsoCercato)
{
AnagraficaStudenti studentiCorso =
new AnagraficaStudenti(numeroStudenti);
for (int i = 0; i < numeroStudenti; ++i) {
String corsoTrovato = studente[i].restituisciCorso();
if (corsoTrovato.equals(corsoCercato)) {
studentiCorso.aggiungi(studente[i]);
}
}
return studentiCorso;
}
// Metodi per la scansione dell'anagrafica studenti
public void iniziaScansione()
{
posizioneCorrente = 0;
}
public Studente prossimoStudente()
{
if (posizioneCorrente < studente.length) {
Studente s = studente[posizioneCorrente];
++posizioneCorrente;
return s;
} else {
return null;
}
}
public int restituisciNumeroStudenti()
{
return numeroStudenti;
}
}
AnagraficaStudenti.java
Created with JBuilder |