Opzione 2 + refactor opzione 1
This commit is contained in:
@@ -17,4 +17,9 @@ public class Concerto extends Evento{
|
||||
this.tipologia_musica = tipologia_musica;
|
||||
this.nome = nome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + "\nTipologia musica: " + this.tipologia_musica + "\nNome band: " + this.nome;
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,9 @@ public class Evento {
|
||||
this.titolo = titolo;
|
||||
this.prezzo = prezzo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Titolo: " + this.titolo + "\nPrezzo: " + this.prezzo;
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,18 @@ public class IncontroCulturale extends Evento{
|
||||
this.relatori = relatori;
|
||||
}
|
||||
|
||||
private String relatoriToString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String relatore : this.relatori) {
|
||||
sb.append(relatore);
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + "\nTema incontro: " + this.tema + "\nRelatori: " + relatoriToString();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
*/
|
||||
package eventitriennale;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Verde
|
||||
@@ -17,4 +19,19 @@ public class Mostra extends Evento {
|
||||
this.nome_artista = nome_artista;
|
||||
this.sale = sale;
|
||||
}
|
||||
|
||||
private String saleToString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String sala : this.sale) {
|
||||
sb.append(sala);
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + "\nNome artista: " + this.nome_artista + "\nSale usate: " + saleToString();
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,6 @@ public class eventiTriennale {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Evento[] eventi = null;
|
||||
String sceltaSiNo;
|
||||
boolean error;
|
||||
int scelta = -1;
|
||||
|
||||
do {
|
||||
@@ -43,31 +41,15 @@ public class eventiTriennale {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (eventi != null) {
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Attenzione: esiste già una lista di eventi. Sovrascriverla? [S/N]");
|
||||
sceltaSiNo = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
switch (sceltaSiNo) {
|
||||
case "s":
|
||||
eventi = inserisciEventi();
|
||||
break;
|
||||
case "n":
|
||||
System.out.println("La lista non è stata modificata.");
|
||||
break;
|
||||
default:
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
} else {
|
||||
eventi = inserisciEventi();
|
||||
}
|
||||
eventi = opzioneUno(eventi);
|
||||
pausa();
|
||||
break;
|
||||
case 2:
|
||||
|
||||
if (eventi == null) {
|
||||
System.out.println("Errore: Non è ancora stata creata una lista di eventi.");
|
||||
} else {
|
||||
mostraEventi(eventi);
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 3:
|
||||
@@ -95,6 +77,34 @@ public class eventiTriennale {
|
||||
sc.nextLine();
|
||||
}
|
||||
|
||||
static Evento[] opzioneUno(Evento[] eventi) {
|
||||
boolean error;
|
||||
String scelta;
|
||||
if (eventi != null) {
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Attenzione: esiste già una lista di eventi. Sovrascriverla? [S/N]");
|
||||
scelta = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
switch (scelta) {
|
||||
case "s":
|
||||
eventi = inserisciEventi();
|
||||
break;
|
||||
case "n":
|
||||
System.out.println("La lista non è stata modificata.");
|
||||
break;
|
||||
default:
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
} else {
|
||||
eventi = inserisciEventi();
|
||||
}
|
||||
|
||||
return eventi;
|
||||
}
|
||||
|
||||
static Evento[] inserisciEventi() {
|
||||
int numeroEventi = dimensione("della lista degli eventi");
|
||||
Evento[] eventi = new Evento[numeroEventi];
|
||||
@@ -271,4 +281,10 @@ public class eventiTriennale {
|
||||
|
||||
return relatori;
|
||||
}
|
||||
|
||||
static void mostraEventi(Evento[] eventi) {
|
||||
for (Evento evento : eventi) {
|
||||
System.out.println(evento.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user