:3
This commit is contained in:
parent
7e467b8f0d
commit
376e06ad67
290
Main.java
Normal file
290
Main.java
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
/** Main
|
||||||
|
* Software per la gestione semplificata di un registro elettronico
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
public static int proveAndateBene = 0;
|
||||||
|
public static int proveAndateMale = 0;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
registraRisultato("studentePassaBadge", provaStudentePassaBadge());
|
||||||
|
registraRisultato("classeAggiungiStudenti", provaClasseAggiungiStudenti());
|
||||||
|
registraRisultato("classeLimiteAggiuntaStudenti", provaClasseLimiteAggiuntaStudenti());
|
||||||
|
registraRisultato("classeLimiteRimozioneStudenti", provaClasseLimiteRimozioneStudenti());
|
||||||
|
registraRisultato("classeRimozioneStudenti", provaClasseRimozioneStudenti());
|
||||||
|
registraRisultato("aggiungiRappresentantiValidi", provaAggiungiRappresentantiValidi());
|
||||||
|
registraRisultato("rimuoviRappresentanti", provaRimuoviRappresentanti());
|
||||||
|
registraRisultato("classeRimuoviStudentiDiAltreClassi", provaClasseRimuoviStudentiDiAltreClassi());
|
||||||
|
registraRisultato("classeAggiungiStudenteInDueClassi", provaClasseAggiungiStudenteInDueClassi());
|
||||||
|
registraRisultato("classeImpostaCoordinatore", provaClasseImpostaCoordinatore());
|
||||||
|
registraRisultato("classeCambiaCoordinatore", provaClasseCambiaCoordinatore());
|
||||||
|
|
||||||
|
System.out.println("Prove andate bene: " + proveAndateBene);
|
||||||
|
System.out.println("Prove andate male: " + proveAndateMale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registraRisultato(String nomeProva, boolean risultato) {
|
||||||
|
System.out.println(nomeProva + ": " + (risultato ? "OK" : "ERRORE"));
|
||||||
|
if(risultato) {
|
||||||
|
proveAndateBene++;
|
||||||
|
} else {
|
||||||
|
proveAndateMale++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////// PROVE //////////////////////////////////////////
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlla che quando uno studente passa il badge viene segnato presente, mentre quando non lo passa viene segnato assente
|
||||||
|
*/
|
||||||
|
public static boolean provaStudentePassaBadge() {
|
||||||
|
Studente studenteA = new Studente("A");
|
||||||
|
Studente studenteB = new Studente("B");
|
||||||
|
Data oggi = new Data(1, 4, 2024);
|
||||||
|
studenteA.passaBadge(oggi);
|
||||||
|
|
||||||
|
return studenteA.registratoPresenza(oggi) && !studenteB.registratoPresenza(oggi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlla che l'aggiunta di degli studenti alla classe funzioni correttamente
|
||||||
|
*/
|
||||||
|
public static boolean provaClasseAggiungiStudenti() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
classe.aggiungiStudente(new Studente("Studente " + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
Studente[] studenti = classe.getStudenti();
|
||||||
|
|
||||||
|
return studenti.length == 3
|
||||||
|
&& studenti[0].getNome().equals("Studente 0")
|
||||||
|
&& studenti[1].getNome().equals("Studente 1")
|
||||||
|
&& studenti[2].getNome().equals("Studente 2")
|
||||||
|
&& studenti[0].classe == classe
|
||||||
|
&& studenti[1].classe == classe
|
||||||
|
&& studenti[2].classe == classe;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlla che non si possano mettere più di 4 studenti in una classe
|
||||||
|
*/
|
||||||
|
public static boolean provaClasseLimiteAggiuntaStudenti() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
|
||||||
|
try {
|
||||||
|
for(int i = 0; i < 5; i++) {
|
||||||
|
classe.aggiungiStudente(new Studente("Studente " + i));
|
||||||
|
}
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlla che non si possano togliere studenti se non se ne hanno più di 2
|
||||||
|
*/
|
||||||
|
public static boolean provaClasseLimiteRimozioneStudenti() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
|
||||||
|
Studente studente1 = new Studente("Studente 1");
|
||||||
|
classe.aggiungiStudente(studente1);
|
||||||
|
Studente studente2 = new Studente("Studente 2");
|
||||||
|
classe.aggiungiStudente(studente2);
|
||||||
|
Studente studente3 = new Studente("Studente 3");
|
||||||
|
classe.aggiungiStudente(studente3);
|
||||||
|
|
||||||
|
try {
|
||||||
|
classe.rimuoivStudente(studente1);
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
// si deve poter togliere uno studente quando se ne hanno 3
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
classe.rimuoivStudente(studente2);
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
// non si deve ppoter togliere uno studente quando se ne hanno 2
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaClasseRimozioneStudenti() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
Studente[] studenti;
|
||||||
|
|
||||||
|
Studente studente1 = new Studente("Studente 1");
|
||||||
|
classe.aggiungiStudente(studente1);
|
||||||
|
Studente studente2 = new Studente("Studente 2");
|
||||||
|
classe.aggiungiStudente(studente2);
|
||||||
|
Studente studente3 = new Studente("Studente 3");
|
||||||
|
classe.aggiungiStudente(studente3);
|
||||||
|
|
||||||
|
studenti = classe.getStudenti();
|
||||||
|
if(studenti.length != 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
classe.rimuoivStudente(studente2);
|
||||||
|
|
||||||
|
studenti = classe.getStudenti();
|
||||||
|
if(studenti.length != 2 || studenti[0] != studente1 || studenti[1] != studente3 || studente2.classe != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
classe.aggiungiStudente(studente2);
|
||||||
|
classe.rimuoivStudente(studente3);
|
||||||
|
|
||||||
|
studenti = classe.getStudenti();
|
||||||
|
if(studenti.length != 2 || studenti[0] != studente1 || studenti[1] != studente2 || studente3.classe != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
classe.aggiungiStudente(studente3);
|
||||||
|
classe.rimuoivStudente(studente1);
|
||||||
|
|
||||||
|
studenti = classe.getStudenti();
|
||||||
|
if(studenti.length != 2 || studenti[0] != studente2 || studenti[1] != studente3 || studente1.classe != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaAggiungiRappresentantiValidi() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
Studente[] studenti;
|
||||||
|
|
||||||
|
Studente studenteNormale1 = new Studente("Studente Normale 1");
|
||||||
|
classe.aggiungiStudente(studenteNormale1);
|
||||||
|
Studente studenteNormale2 = new Studente("Studente Normale 2");
|
||||||
|
classe.aggiungiStudente(studenteNormale2);
|
||||||
|
Studente studenteRappresentante1 = new Studente("Studente Rappresentante 1");
|
||||||
|
classe.aggiungiStudente(studenteRappresentante1);
|
||||||
|
Studente studenteRappresentante2 = new Studente("Studente Rappresentante 2");
|
||||||
|
classe.aggiungiStudente(studenteRappresentante2);
|
||||||
|
|
||||||
|
try {
|
||||||
|
classe.aggiungiRappresentante(studenteRappresentante1);
|
||||||
|
classe.aggiungiRappresentante(studenteRappresentante2);
|
||||||
|
} catch(IllegalArgumentException | IllegalStateException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
studenti = classe.getRappresentanti();
|
||||||
|
return studenti.length == 2
|
||||||
|
&& studenti[0] == studenteRappresentante1
|
||||||
|
&& studenti[1] == studenteRappresentante2
|
||||||
|
&& studenteRappresentante1.rappresentante
|
||||||
|
&& studenteRappresentante2.rappresentante
|
||||||
|
&& !studenteNormale1.rappresentante
|
||||||
|
&& !studenteNormale2.rappresentante;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaAggiungiRappresentantiDiAltraClasse() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
Classe altraClasse = new Classe();
|
||||||
|
|
||||||
|
Studente studenteDiAltraClasse = new Studente("Studente dell'altra classe");
|
||||||
|
altraClasse.aggiungiStudente(studenteDiAltraClasse);
|
||||||
|
|
||||||
|
try {
|
||||||
|
classe.aggiungiRappresentante(studenteDiAltraClasse);
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaRimuoviRappresentanti() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
|
||||||
|
Studente rappresentante1 = new Studente("rappresentante");
|
||||||
|
classe.aggiungiStudente(rappresentante1);
|
||||||
|
classe.aggiungiRappresentante(rappresentante1);
|
||||||
|
Studente rappresentante2 = new Studente("rappresentante");
|
||||||
|
classe.aggiungiStudente(rappresentante2);
|
||||||
|
classe.aggiungiRappresentante(rappresentante2);
|
||||||
|
|
||||||
|
if(classe.getRappresentanti().length != 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
classe.rimuoviRappresentante(rappresentante1);
|
||||||
|
|
||||||
|
Studente[] studenti = classe.getRappresentanti();
|
||||||
|
return studenti.length == 1 && studenti[0] == rappresentante2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaClasseRimuoviStudentiDiAltreClassi() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
Classe altraClasse = new Classe();
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
classe.aggiungiStudente(new Studente("a"));
|
||||||
|
}
|
||||||
|
Studente studente = new Studente("Studente di un'altra classe");
|
||||||
|
altraClasse.aggiungiStudente(studente);
|
||||||
|
|
||||||
|
try {
|
||||||
|
classe.rimuoivStudente(studente);
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaClasseAggiungiStudenteInDueClassi() {
|
||||||
|
Studente studente = new Studente("a");
|
||||||
|
|
||||||
|
Classe classe1 = new Classe();
|
||||||
|
Classe classe2 = new Classe();
|
||||||
|
|
||||||
|
try {
|
||||||
|
classe1.aggiungiStudente(studente);
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
classe2.aggiungiStudente(studente);
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaClasseImpostaCoordinatore() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
Insegnante insegnante = new Insegnante("Insegnante", 40, new Materia("Italiano"));
|
||||||
|
|
||||||
|
if(classe.getCoordinatore() != null || insegnante.classeCoordinata != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
classe.setCoordinatore(insegnante);
|
||||||
|
|
||||||
|
return classe.getCoordinatore() == insegnante && insegnante.classeCoordinata == classe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean provaClasseCambiaCoordinatore() {
|
||||||
|
Classe classe = new Classe();
|
||||||
|
Insegnante insegnante = new Insegnante("Insegnante", 40, new Materia("Italiano"));
|
||||||
|
|
||||||
|
classe.setCoordinatore(insegnante);
|
||||||
|
|
||||||
|
Insegnante altroInsegnante = new Insegnante("Altro Insegnante", 50, new Materia("Matematica"));
|
||||||
|
|
||||||
|
classe.setCoordinatore(altroInsegnante);
|
||||||
|
|
||||||
|
return classe.getCoordinatore() == altroInsegnante && altroInsegnante.classeCoordinata == classe && insegnante.classeCoordinata == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user