Mostra follower influencer

This commit is contained in:
La Programmatrice Verde 2025-10-17 17:18:36 +02:00
parent 4ae444e617
commit f20411fcd8
3 changed files with 60 additions and 3 deletions

View File

@ -24,4 +24,8 @@ public class Influencer extends Persona{
System.out.println("Numero di follower: " + this.numeroFollower); System.out.println("Numero di follower: " + this.numeroFollower);
System.out.println("Handle: " + this.handle); System.out.println("Handle: " + this.handle);
} }
public String getNumeroFollower() {
return this.numeroFollower;
}
} }

View File

@ -28,4 +28,8 @@ public class Persona {
System.out.println("Sesso: " + this.sesso); System.out.println("Sesso: " + this.sesso);
System.out.println("Età: " + this.età); System.out.println("Età: " + this.età);
} }
public String getNome() {
return this.nome;
}
} }

View File

@ -24,6 +24,8 @@ public class ereditarieta {
int scelta = -1; int scelta = -1;
Persona persone[] = null; Persona persone[] = null;
boolean opzione1 = false; boolean opzione1 = false;
String nome;
Influencer influencerDaMostrare;
do { do {
System.out.println("Scegliere un'opzione:"); System.out.println("Scegliere un'opzione:");
@ -51,12 +53,35 @@ public class ereditarieta {
if (opzione1) { if (opzione1) {
MostraPersone(persone); MostraPersone(persone);
} else { } else {
System.out.println("Errore: è necessario aggiungere almeno una persona prima di mostrarle."); System.out
.println("Errore: è necessario aggiungere almeno una persona prima di mostrarle.");
} }
Pausa(); Pausa();
break; break;
case 3: case 3:
if (opzione1) {
if (ProfessioneEsiste(persone, "Influencer")) {
System.out.print("Inserire il nome dell'influencer: ");
nome = sc.nextLine();
if ((influencerDaMostrare = (Influencer) TrovaPersonaPerNomeeProfessione(persone, nome,
"Influencer")) != null) {
System.out.println("L'influencer di nome " + nome + " ha "
+ influencerDaMostrare.getNumeroFollower() + " follower.");
} else {
System.out
.println("Errore: l'influencer di nome " + nome + " non è stato trovato.");
}
} else {
System.out
.println(
"Errore: è necessario aggiungere almeno un influencer prima di mostrare i suoi follower.");
}
} else {
System.out
.println(
"Errore: è necessario aggiungere almeno una persona prima di mostrare informazioni su di esse.");
}
Pausa(); Pausa();
break; break;
case 4: case 4:
@ -121,8 +146,7 @@ public class ereditarieta {
if (p_persone == null) { if (p_persone == null) {
ritorno = new Persona[numeroPersone]; ritorno = new Persona[numeroPersone];
} } else {
else {
ritorno = Arrays.copyOf(p_persone, p_persone.length + numeroPersone, p_persone.getClass()); ritorno = Arrays.copyOf(p_persone, p_persone.length + numeroPersone, p_persone.getClass());
} }
@ -207,4 +231,29 @@ public class ereditarieta {
System.out.println(); System.out.println();
} }
} }
static boolean ProfessioneEsiste(Persona[] p_persone, String p_professione) {
boolean ritorno = false;
for (int i = 0; i < p_persone.length && !ritorno; i++) {
if (p_persone[i].getClass().getSimpleName().equals(p_professione)) {
ritorno = true;
}
}
return ritorno;
}
static Persona TrovaPersonaPerNomeeProfessione(Persona[] p_persone, String p_nome, String p_professione) {
Persona ritorno = null;
boolean error = true;
for (int i = 0; i < p_persone.length && error; i++) {
if (p_persone[i].getClass().getSimpleName().equals(p_professione) && p_persone[i].getNome().equals(p_nome)) {
error = false;
ritorno = p_persone[i];
}
}
return ritorno;
}
} }