Mostra tutti studenti che hanno l'età minima
This commit is contained in:
parent
a15480da14
commit
33a4618a18
@ -27,6 +27,7 @@ public class ereditarieta {
|
|||||||
String nome;
|
String nome;
|
||||||
Influencer influencerDaMostrare = null;
|
Influencer influencerDaMostrare = null;
|
||||||
Calciatore calciatoreDaMostrare = null;
|
Calciatore calciatoreDaMostrare = null;
|
||||||
|
Studente studentiDaMostrare[] = null;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
System.out.println("Scegliere un'opzione:");
|
System.out.println("Scegliere un'opzione:");
|
||||||
@ -107,16 +108,26 @@ public class ereditarieta {
|
|||||||
case 5:
|
case 5:
|
||||||
if (opzione1) {
|
if (opzione1) {
|
||||||
if (professioneEsiste(persone, "Studente")) {
|
if (professioneEsiste(persone, "Studente")) {
|
||||||
int minimo = Integer.MAX_VALUE, j = 0;
|
|
||||||
Studente studenti[] = trovaStudenti(persone);
|
Studente studenti[] = trovaStudenti(persone);
|
||||||
|
|
||||||
|
int minimo = Integer.MAX_VALUE, j = 0;
|
||||||
for (int i = 0; i < studenti.length; i++) {
|
for (int i = 0; i < studenti.length; i++) {
|
||||||
if (Integer.parseInt(studenti[i].getEtà()) < minimo) {
|
if (Integer.parseInt(studenti[i].getEtà()) < minimo) {
|
||||||
minimo = Integer.parseInt(studenti[i].getEtà());
|
minimo = Integer.parseInt(studenti[i].getEtà());
|
||||||
j = i;
|
j = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
studentiDaMostrare = trovaStudentiPerEtà(persone, String.valueOf(minimo));
|
||||||
|
if (studentiDaMostrare.length == 1) {
|
||||||
System.out.println("Lo studente più giovane è:");
|
System.out.println("Lo studente più giovane è:");
|
||||||
studenti[j].mostraPersona();
|
studenti[j].mostraPersona();
|
||||||
|
} else {
|
||||||
|
for (Studente studente : studentiDaMostrare) {
|
||||||
|
studente.mostraPersona();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out
|
System.out
|
||||||
.println(
|
.println(
|
||||||
@ -225,7 +236,8 @@ public class ereditarieta {
|
|||||||
|
|
||||||
System.out.print("Inserire l'indirizzo di studio: ");
|
System.out.print("Inserire l'indirizzo di studio: ");
|
||||||
indirizzoDiStudio = sc.nextLine();
|
indirizzoDiStudio = sc.nextLine();
|
||||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Studente(nome, cognome, sesso, età, classe, indirizzoDiStudio);
|
ritorno[arrayNuovo ? i : p_persone.length + i] = new Studente(nome, cognome, sesso, età,
|
||||||
|
classe, indirizzoDiStudio);
|
||||||
error = false;
|
error = false;
|
||||||
System.out.println("Studente inserito con successo.");
|
System.out.println("Studente inserito con successo.");
|
||||||
break;
|
break;
|
||||||
@ -235,7 +247,8 @@ public class ereditarieta {
|
|||||||
|
|
||||||
System.out.print("Inserire il numero di maglia: ");
|
System.out.print("Inserire il numero di maglia: ");
|
||||||
numeroMaglia = sc.nextLine();
|
numeroMaglia = sc.nextLine();
|
||||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Calciatore(nome, cognome, sesso, età, squadra, numeroMaglia);
|
ritorno[arrayNuovo ? i : p_persone.length + i] = new Calciatore(nome, cognome, sesso, età,
|
||||||
|
squadra, numeroMaglia);
|
||||||
error = false;
|
error = false;
|
||||||
System.out.println("Calciatore inserito con successo.");
|
System.out.println("Calciatore inserito con successo.");
|
||||||
break;
|
break;
|
||||||
@ -245,7 +258,8 @@ public class ereditarieta {
|
|||||||
|
|
||||||
System.out.print("Inserire l'handle: ");
|
System.out.print("Inserire l'handle: ");
|
||||||
handle = sc.nextLine();
|
handle = sc.nextLine();
|
||||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Influencer(nome, cognome, sesso, età, numeroFollower, handle);
|
ritorno[arrayNuovo ? i : p_persone.length + i] = new Influencer(nome, cognome, sesso, età,
|
||||||
|
numeroFollower, handle);
|
||||||
error = false;
|
error = false;
|
||||||
System.out.println("Influencer inserito con successo.");
|
System.out.println("Influencer inserito con successo.");
|
||||||
break;
|
break;
|
||||||
@ -300,10 +314,25 @@ public class ereditarieta {
|
|||||||
static Studente[] trovaStudenti(Persona[] p_persone) {
|
static Studente[] trovaStudenti(Persona[] p_persone) {
|
||||||
Studente ritorno[] = new Studente[0];
|
Studente ritorno[] = new Studente[0];
|
||||||
|
|
||||||
for (int i = 0; i < p_persone.length; i++) {
|
for (int i = 0, j = 0; i < p_persone.length; i++) {
|
||||||
if (p_persone[i].getClass().getSimpleName().equals("Studente")) {
|
if (p_persone[i].getClass().getSimpleName().equals("Studente")) {
|
||||||
ritorno = Arrays.copyOf(ritorno, ritorno.length + 1, ritorno.getClass());
|
ritorno = Arrays.copyOf(ritorno, ritorno.length + 1, ritorno.getClass());
|
||||||
ritorno[i] = (Studente) p_persone[i];
|
ritorno[j] = (Studente) p_persone[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Studente[] trovaStudentiPerEtà(Persona[] p_persone, String p_età) {
|
||||||
|
Studente ritorno[] = new Studente[0];
|
||||||
|
|
||||||
|
for (int i = 0, j = 0; i < p_persone.length; i++) {
|
||||||
|
if (p_persone[i].getEtà().equals(p_età)) {
|
||||||
|
ritorno = Arrays.copyOf(ritorno, ritorno.length + 1, ritorno.getClass());
|
||||||
|
ritorno[j] = (Studente) p_persone[i];
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user