package com.gradescope.hw07; // ArrayLists are common and helpful! // Read more about how to use ArrayLists: // http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html import java.util.ArrayList; /* * Table class models a table with chairs and people. */ public class Table { int chairCount; int personCount; ArrayList people; /* * Table() * * Table constructor makes a Table object that has 5 seats. */ public Table() { // set the chairCount to 5 by default this(5); } /* * Table(int capacity) * * Table constructor where the input determines the size of the Table. * Throws an IllegalArgumentException if the argument is less than 0. */ public Table(int capacity) { if (capacity < 0) { throw new IllegalArgumentException( "Tables must start with a capacity of 0 or more"); } this.chairCount = capacity; this.personCount = 0; this.people = new ArrayList(); } /* * emptySeat() * * returns true if there are fewer people than seats. */ public boolean emptySeat() { return this.personCount < this.chairCount; } /* * addPerson(String name) * * adds the new person to the table by updating the personCount variable and * the list of names. * returns a String welcoming the person to the table. */ public String addPerson(String name) { if (this.emptySeat()) { this.personCount++; this.people.add(name); return "Welcome " + name; } else { return "Sorry - there is no space for you " + name; } } /* * removePerson(String name) * * removes a person from the table. * returns a salutation. */ public String removePerson(String name) { boolean wasRemoved = this.people.remove(name); if (!wasRemoved) { return "Weird! " + name + " was never here!"; } this.personCount--; if (this.personCount == 0) { return "(Silence - no one is here to say goodbye)"; } else { return "Bye " + name; } } }