finish lab8
This commit is contained in:
parent
cd6bd96b94
commit
7b9c562053
@ -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:";
|
||||
|
@ -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());
|
||||
}
|
||||
|
Reference in New Issue
Block a user