Opzione 4
This commit is contained in:
@@ -21,4 +21,8 @@ public class Evento {
|
||||
public String toString() {
|
||||
return "Titolo: " + this.titolo + "\nPrezzo: " + this.prezzo;
|
||||
}
|
||||
|
||||
public void sconto(float quantita) {
|
||||
this.prezzo -= this.prezzo / 100 * quantita;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public class eventiTriennale {
|
||||
|
||||
static Scanner sc = new Scanner(System.in);
|
||||
static final String ERRORE_GENERICO = "Errore: opzione non valida.";
|
||||
static final String ERRORE_EVENTI_VUOTO = "Errore: Non è ancora stata creata una lista di eventi.";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Evento[] eventi = null;
|
||||
@@ -47,7 +48,7 @@ public class eventiTriennale {
|
||||
break;
|
||||
case 2:
|
||||
if (eventi == null) {
|
||||
System.out.println("Errore: Non è ancora stata creata una lista di eventi.");
|
||||
System.out.println();
|
||||
} else {
|
||||
mostraEventi(eventi);
|
||||
}
|
||||
@@ -55,7 +56,7 @@ public class eventiTriennale {
|
||||
break;
|
||||
case 3:
|
||||
if (eventi == null) {
|
||||
System.out.println("Errore: Non è ancora stata creata una lista di eventi.");
|
||||
System.out.println(ERRORE_EVENTI_VUOTO);
|
||||
} else {
|
||||
concertiTrovati = trovaConcertoPerTipologiaMusica(eventi, "classica");
|
||||
if (!concertiTrovati.isEmpty()) {
|
||||
@@ -67,7 +68,11 @@ public class eventiTriennale {
|
||||
pausa();
|
||||
break;
|
||||
case 4:
|
||||
|
||||
if (eventi == null) {
|
||||
System.out.println(ERRORE_EVENTI_VUOTO);
|
||||
} else {
|
||||
scontoCinquePerCentoMostre(eventi);
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
default:
|
||||
@@ -310,4 +315,12 @@ public class eventiTriennale {
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static void scontoCinquePerCentoMostre(Evento[] eventi) {
|
||||
for (Evento evento : eventi) {
|
||||
if (evento instanceof Mostra) {
|
||||
evento.sconto(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user