COMP2396
Loading...
Searching...
No Matches
tutorial4.part3.q4.Restaurant Class Reference
Collaboration diagram for tutorial4.part3.q4.Restaurant:

Public Member Functions

 Restaurant (String name)
 
void add_table (String name, int capacity)
 
String getName ()
 
String make_reservation (int n)
 

Private Member Functions

String _make_reservation_formatter (Table table, int n)
 

Private Attributes

final String name
 
final ArrayList< Table > tables = new ArrayList<>()
 

Detailed Description

Definition at line 41 of file Restaurant.java.

Constructor & Destructor Documentation

◆ Restaurant()

tutorial4.part3.q4.Restaurant.Restaurant ( String name)
inline

Definition at line 45 of file Restaurant.java.

45 {
46 this.name = name;
47 }

References tutorial4.part3.q4.Restaurant.name.

Member Function Documentation

◆ _make_reservation_formatter()

String tutorial4.part3.q4.Restaurant._make_reservation_formatter ( Table table,
int n )
inlineprivate

Definition at line 57 of file Restaurant.java.

57 {
58 return String.format("Table %s for %d guest(s).", table.getName(), n);
59 }

Referenced by tutorial4.part3.q4.Restaurant.make_reservation().

Here is the caller graph for this function:

◆ add_table()

void tutorial4.part3.q4.Restaurant.add_table ( String name,
int capacity )
inline

Definition at line 53 of file Restaurant.java.

53 {
54 tables.add(new Table(name, capacity));
55 }
final ArrayList< Table > tables

References tutorial4.part3.q4.Restaurant.name, and tutorial4.part3.q4.Restaurant.tables.

Referenced by tutorial4.part3.q4.Main.main().

Here is the caller graph for this function:

◆ getName()

String tutorial4.part3.q4.Restaurant.getName ( )
inline

Definition at line 49 of file Restaurant.java.

49 {
50 return name;
51 }

References tutorial4.part3.q4.Restaurant.name.

◆ make_reservation()

String tutorial4.part3.q4.Restaurant.make_reservation ( int n)
inline

Definition at line 60 of file Restaurant.java.

60 {
61 for (Table table : tables) {
62 // if table fits all people perfectly
63 if (table.getCapacity() == n && table.make_reservation(n)) {
64 return _make_reservation_formatter(table, n);
65 }
66 }
67 // Finds table that don't have anyone
68 for (Table table : tables) {
69 if (table.getReserved() == 0 && table.make_reservation(n)) {
70 return _make_reservation_formatter(table, n);
71 }
72 }
73 // Finds table that does not fit all people perfectly
74 for (Table table : tables) {
75 if (table.getAvailable() >= n && table.make_reservation(n)) {
76 return _make_reservation_formatter(table, n);
77 }
78 }
79 return String.format("No table available for %s guest(s).", n);
80 }
String _make_reservation_formatter(Table table, int n)

References tutorial4.part3.q4.Restaurant._make_reservation_formatter(), and tutorial4.part3.q4.Restaurant.tables.

Referenced by tutorial4.part3.q4.Main.main().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ name

final String tutorial4.part3.q4.Restaurant.name
private

◆ tables

final ArrayList<Table> tutorial4.part3.q4.Restaurant.tables = new ArrayList<>()
private

The documentation for this class was generated from the following file: