Aggiunti i cicli for potenziati in sostituzione a i vecchi for vecchi inzio sviluppo per array list
This commit is contained in:
parent
2263174bfc
commit
f7f0a26361
|
@ -1,10 +1,3 @@
|
|||
/**
|
||||
* Classe Cinema che va a rappresentare un cinema
|
||||
*
|
||||
* @autor Ciausu Angelo
|
||||
* @version 1.1.7
|
||||
* */
|
||||
|
||||
public class Cinema {
|
||||
|
||||
private String nome;
|
||||
|
@ -20,7 +13,6 @@ public class Cinema {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Aggiunge un film all'array di film.
|
||||
*
|
||||
|
@ -34,7 +26,7 @@ public class Cinema {
|
|||
if (film[i] == null) {
|
||||
film[i] = f;
|
||||
break;
|
||||
} else if (film[i] == f) {
|
||||
} else if (film[i].equals(f)) {
|
||||
System.out.println("Film già presente");
|
||||
break;
|
||||
}
|
||||
|
@ -51,12 +43,12 @@ public class Cinema {
|
|||
*
|
||||
* @param Posti il numero di posti da prenotare
|
||||
* @param film il film per cui prenotare i posti
|
||||
* @return `true se i posti sono stati prenotati con successo, `false` altrimenti
|
||||
* @return `true` se i posti sono stati prenotati con successo, `false` altrimenti
|
||||
*/
|
||||
public boolean prenotaPosti(int Posti, Film film) {
|
||||
for (int i = 0; i < this.film.length; i++) {
|
||||
if (this.film[i] != null && this.film[i].equals(film)) {
|
||||
return this.film[i].vendiBiglietti(Posti);
|
||||
for (Film f : this.film) {
|
||||
if (f != null && f.equals(film)) {
|
||||
return f.vendiBiglietti(Posti);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -72,11 +64,9 @@ public class Cinema {
|
|||
*/
|
||||
public Film filmPiùLungo() {
|
||||
Film filmPiuLungo = this.film[0];
|
||||
for (int i = 0; i < this.film.length; i++) {
|
||||
if (this.film[i] != null) {
|
||||
if (this.film[i].getDurata() > filmPiuLungo.getDurata()) {
|
||||
filmPiuLungo = this.film[i];
|
||||
}
|
||||
for (Film f : this.film) {
|
||||
if (f != null && f.getDurata() > filmPiuLungo.getDurata()) {
|
||||
filmPiuLungo = f;
|
||||
}
|
||||
}
|
||||
return new Film(filmPiuLungo.getTitolo(), filmPiuLungo.getDurata(), filmPiuLungo.getSala(), filmPiuLungo.getPostiDisponibili());
|
||||
|
@ -91,10 +81,10 @@ public class Cinema {
|
|||
* @param film il film per cui calcolare la percentuale di posti occupati
|
||||
*/
|
||||
public void percentualePostiOccupati(Film film) {
|
||||
for (int i = 0; i < this.film.length; i++) {
|
||||
if (this.film[i] != null && this.film[i].equals(film)) {
|
||||
int postiTotali = this.film[i].getPostiTotali();
|
||||
int postiDisponibili = this.film[i].getPostiDisponibili();
|
||||
for (Film f : this.film) {
|
||||
if (f != null && f.equals(film)) {
|
||||
int postiTotali = f.getPostiTotali();
|
||||
int postiDisponibili = f.getPostiDisponibili();
|
||||
int postiOccupati = postiTotali - postiDisponibili;
|
||||
double percentuale = (double) postiOccupati / postiTotali * 100;
|
||||
System.out.println("Percentuale posti occupati: " + percentuale + "%");
|
||||
|
@ -115,11 +105,10 @@ public class Cinema {
|
|||
}
|
||||
|
||||
public void stampaProgrammazione() {
|
||||
for (int i = 0; i < this.film.length; i++) {
|
||||
if (this.film[i] != null) {
|
||||
System.out.println("Titolo: " + this.film[i].getTitolo() + " Durata: " + this.film[i].getDurata() + " Sala: " + this.film[i].getSala() + " Posti: " + this.film[i].getPostiDisponibili());
|
||||
for (Film f : this.film) {
|
||||
if (f != null) {
|
||||
System.out.println("Titolo: " + f.getTitolo() + " Durata: " + f.getDurata() + " Sala: " + f.getSala() + " Posti: " + f.getPostiDisponibili());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue