first part of lab 8

This commit is contained in:
2021-12-12 18:01:08 +01:00
parent 7a0d8f3cca
commit cd6bd96b94
17 changed files with 511 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,19 @@
package lab8_tableaux;
public class Seat {
public boolean busy;
private char row;
private int column;
Seat(char row, int column){
this.row = row;
this.column = column;
}
public String getPlace(){
String s = "";
s += this.column;
s += this.row;
return s;
}
}

View File

@@ -0,0 +1,19 @@
package lab8_tableaux;
public class Task0 {
public static void main(String[] args) {
int[] foo = even_array(5);
for (int i = 0; i < foo.length; i++) {
System.out.println(foo[i]);
}
}
public static int[] even_array(int n){
int[] foo = new int[n];
for (int i = 0; i < foo.length; i++) {
foo[i] = i*2;
}
return foo;
}
}

View File

@@ -0,0 +1,8 @@
package lab8_tableaux;
public class Task1 {
public static void main(String[] args) {
Seat mySeat = new Seat('a', 7);
System.out.println(mySeat.busy);
}
}

View File

@@ -0,0 +1,104 @@
package lab8_tableaux;
public class Theater {
private Seat[][] seats;
Theater(int r, int c){
seats = new Seat[c][r];
for (int i = 1; i <= c; i++) {
for (char j = 'A'; j < 'A'+r; j++) {
seats[i-1][j-'A'] = new Seat(j,i);
}
}
}
public String getSeat(int row, int column){
return seats[column][row].getPlace();
}
public boolean isSeatBusy (int row, int column){
return seats[column][row].busy;
}
public boolean occupySeat(int row, int column) {
if (isSeatBusy(row, column)) {
return false;
}
seats[column][row].busy = true;
return true;
}
private int numberOfBusySeats(){
int total =0 ;
int r = seats[0].length;
int c = seats.length;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if(isSeatBusy(i, j)){
total++;
}
}
}
return total;
}
private int numberOfSeats(){
int total =0 ;
int r = seats[0].length;
int c = seats.length;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
total++;
}
}
return total;
}
public String occupation() {
String s = "";
s += "Theater occupation: ";
s += numberOfBusySeats();
s += " / ";
s += numberOfSeats();
return s;
}
public String toString(){
String s = "";
s += "Theater seats occupation:";
s += "\n";
s += "\n";
s += " ";
int r = seats[0].length;
int c = seats.length;
System.out.println(c + "x" + r);
for (int i = 0; i < c; i++) {
s += " ";
s += i;
}
s += "\n";
for (int i = 0; i < r; i++) {
s += i;
s += " ";
for (int j = 0; j < c; j++) {
if (isSeatBusy(i, j)) {
s += "X";
} else {
s += " ";
}
s += space(j);
}
s += "\n";
}
return s;
}
private String space (int i){
String s = "";
int length = String.valueOf(i).length();
for (int j = 0; j < length; j++) {
s += " ";
}
return s;
}
}

View File

@@ -0,0 +1,24 @@
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);
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);
System.out.println(cinema);
System.out.println(cinema.occupation());
}
}