// part 1
/**
* This class ...
*/
A group (of people) dining together, and should be seated at the same table.
* We currently only need to handle the size.
*/
public class Group {
/**
* Initializes this Group with the provided guest count
*/
public Group(int guestCount) {
...
}
}
/**
* A table with a certain maximum capacity.
*/
public class Table {
/**
* Initializes this Table with the provided capacity.
* The table is also assigned a unique number.
* @param capacity
*/
public Table(int capacity) {
...
}
/**
* @return the table number
*/
public int getNum() {
...
}
}
/**
* Represents the fact that a Group is seated at and occupies a Table
*/
public class Seating {
/**
* Initializes this Seating ...
*/
public Seating(...) {
...
}
}
// part 2
/**
* A place where groups of guests can buy a meal
*/
public class Diner {
/**
* Tells whether a Table is occupied.
* @param table the Table to check
* @return true if anyone is sitting at the provided Table
*/
public boolean isOccupied(Table table) {
...
}
/**
* Computes the guest capacity,
* either the remaining (includeOccupied == false) or total (includeOccupied == true).
* @param includeOccupied controls whether to include tables that are occupied.
* @return the guest capacity
*/
public int getCapacity(boolean includeOccupied) {
...
}
/**
* Adds a table to this Diner
* @param table
*/
public void addTable(Table table) {
...
}
/**
* Removes a Table from this Diner.
* If the table is occupied an IllegalArgumentException exception should be thrown.
* @param table
* @throws IllegalArgumentException
*/
public void removeTable(Table table) {
...
}
/**
* Merges two tables, i.e. replaces two tables with one table.
* lostCapacity is the difference between the old capacity and the new.
* This number is typically positive, since seats are lost when moving two tables
* close to each other.
* @param table1
* @param table2
* @param lostCapacity
* @throws IllegalArgumentException if any of the tables are occupied
*/
public void mergeTables(Table table1, Table table2, int lostCapacity) {
...
}
/**
* Splits a table into two, i.e. replaces one tables with two tables.
* The two capacities are the capacities of the two new tables.
* @param table
* @param capacity1
* @param capacity2
* @throws IllegalArgumentException if the table is occupied
*/
public void splitTable(Table table, int capacity1, int capacity2) {
...
}
/**
* Tells whether a table has the provided capacity,
* i.e. if that number of new guests can be seated there.
* Note that a table cannot be shared among different groups.
* @param table
* @param capacity
* @return true of capacity number of guests can be seated here, false otherwise.
*/
public boolean hasCapacity(Table table, int capacity) {
...
}
/**
* Returns the tables that has the provided capacity.
* The tables should be sorted with the one with the least capacity (but enough) first.
* @param capacity
* @return the tables that has the provided capacity
*/
public Collection<Table> findAvailableTables(int capacity) {
...
}
/**
* Finds a suitable, existing table for the provided group, and creates
* (but doesn't add) a corresponding Seating.
* The chosen table should be the one with the least capacity.
* @param group the group to be seated
* @return the newly created Seating
*/
public Seating createSeating(Group group) {
...
}
/**
* Creates and adds a Seating for the provided group, using the createSeating method.
* @param group
* @return true if a Seating was created and added, false otherwise.
*/
public boolean addSeating(Group group) {
...
}
/**
* Removes the seating for the provided table (number), if one exists
* @param tableNum the number of the table to be removed
*/
public void removeSeating(int tableNum) {
...
}
}
// part 3
public class SimpleTable ... Table {
public SimpleTable(int capacity) {
...
}
...
}
/**
* A table that consists of two other tables.
*/
public class CompositeTable ... Table {
public CompositeTable(Table table1, Table table2, int lostCapacity) {
...
}
...
}
// part 4
/**
* Interface for listening to changes in Diner capacity
*/
public interface CapacityListener {
/**
* Called to inform that a Diner has changed capacity
* @param diner
*/
public void capacityChanged(Diner diner);
}
/**
* Handles guests arriving at and departing from a Diner.
*/
public class GuestManager ... {
public GuestManager(Diner diner) {
...
}
/**
* Handles arriving groups, by either seating them immediately
* (if possible) or putting them in queue. Those enqueued will
* be seated when the Diner's (change in) capacity allows.
* @param group
*/
public void groupArrived(Group group) {
...
}
/**
* Handles departing groups, by removing their seating.
* @param tableNum the table where the group was seated
*/
public void groupDeparted(int tableNum) {
...
}
...
}
|