package com.gradescope.hw07; import java.util.ArrayList; public class HochTable { int chairCount; int personCount; ArrayList people; /* * Constructor for HochTable */ public HochTable(){ // By default, HochTables have 6 chairs. this(6); } /* * HochTable(int capacity) * * HochTable constructor where the input determines the size of the Table. * Throws an IllegalArgumentException if the argument is less than 0. */ public HochTable(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() * * Hoch tables are never full! * returns true. */ public boolean emptySeat(){ // Hoch tables are never full! N+1 return true; } /* * 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.chairCount == this.personCount){ this.chairCount++; } // return a greeting to the person! 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; } } /* * classStartingSoon() * * removes everyone from the table. */ public void classStartingSoon(){ this.personCount = 0; this.people = new ArrayList(); } }