1package tutorial4.part3.q4;
3import java.util.ArrayList;
6 private final String name;
7 private final int capacity;
8 private int reserved = 0;
10 public Table(String name,
int capacity) {
12 this.capacity = capacity;
15 public String getName() {
19 public int getCapacity() {
23 public int getReserved() {
27 public int getAvailable() {
28 return getCapacity() - getReserved();
31 public boolean make_reservation(
int n) {
32 if (reserved + n <= capacity) {
43 private final ArrayList<Table>
tables =
new ArrayList<>();
58 return String.format(
"Table %s for %d guest(s).", table.getName(), n);
61 for (Table table :
tables) {
63 if (table.getCapacity() == n && table.make_reservation(n)) {
68 for (Table table :
tables) {
69 if (table.getReserved() == 0 && table.make_reservation(n)) {
74 for (Table table :
tables) {
75 if (table.getAvailable() >= n && table.make_reservation(n)) {
79 return String.format(
"No table available for %s guest(s).", n);
String make_reservation(int n)
void add_table(String name, int capacity)
String _make_reservation_formatter(Table table, int n)
final ArrayList< Table > tables