finish lab8

This commit is contained in:
Rémi Heredero 2021-12-16 14:51:37 +01:00
parent cd6bd96b94
commit 7b9c562053
2 changed files with 54 additions and 13 deletions

View File

@ -63,6 +63,40 @@ public class Theater {
return s;
}
private String[] getContiguousSeats(int nbrOfSeat){
String[] contiguousSeats = new String[nbrOfSeat];
int contiguous =0 ;
int r = seats[0].length;
int c = seats.length;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
contiguous = isSeatBusy(i, j) ? 0:contiguous+1;
if (contiguous >= nbrOfSeat) {
for (int k = 1; k <= contiguous; k++) {
occupySeat(i, (j-contiguous+k));
contiguousSeats[k-1] = getSeat(i, (j-contiguous+k));
}
return contiguousSeats;
}
}
}
return null;
}
public String reserveSeat(int nbrOfSeat){
String s = "";
String[] reservedSeats = getContiguousSeats(nbrOfSeat);
if(reservedSeats != null){
s += "Got the contiguous seats : \n";
for(int i = 0; i < reservedSeats.length; i++){
s += "-" + reservedSeats[i] + "\n";
}
} else {
s += "Could not get contiguous seats";
}
return s;
}
public String toString(){
String s = "";
s += "Theater seats occupation:";

View File

@ -3,21 +3,28 @@ package lab8_tableaux;
public class TheaterApplication {
public static void main(String[] args) {
Theater cinema = new Theater(10, 20);
cinema.occupySeat(2, 1);
cinema.occupySeat(2, 3);
cinema.occupySeat(2, 5);
cinema.occupySeat(2, 8);
Theater cinema = new Theater(7, 11);
cinema.occupySeat(0, 1);
cinema.occupySeat(0, 3);
cinema.occupySeat(0, 5);
cinema.occupySeat(0, 8);
cinema.occupySeat(0, 9);
cinema.occupySeat(0, 10);
cinema.occupySeat(0, 11);
cinema.occupySeat(0, 13);
cinema.occupySeat(0, 15);
cinema.occupySeat(0, 18);
cinema.occupySeat(0, 6);
cinema.occupySeat(0, 7);
cinema.occupySeat(1, 0);
cinema.occupySeat(1, 1);
cinema.occupySeat(1, 5);
cinema.occupySeat(3, 3);
cinema.occupySeat(3, 7);
cinema.occupySeat(4, 7);
cinema.occupySeat(5, 5);
cinema.occupySeat(5, 8);
cinema.occupySeat(6, 8);
System.out.println(cinema);
System.out.println(cinema.occupation());
System.out.println(cinema.reserveSeat(4));
System.out.println(cinema);
System.out.println(cinema.occupation());
System.out.println(cinema.reserveSeat(2));
System.out.println(cinema);
System.out.println(cinema.occupation());
}