package com.gradescope.hw07; import java.util.ArrayList; /* * Just like a HochTable, but whenever a person is added, * they say hello to everyone else at the table! */ public class SuperFriendlyHochTable { int chairCount; int personCount; ArrayList people; /* * Constructor for SuperFriendlyHochTable */ public SuperFriendlyHochTable(){ // By default, SuperFriendlyHochTable have 10 chairs. this(10); } /* * SuperFriendlyHochTable(int capacity) * * SuperFriendlyHochTable constructor where the input determines the size of the Table. * Throws an IllegalArgumentException if the argument is less than 0. */ public SuperFriendlyHochTable(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); } String allNames = this.people.toString(); return "Hello " + allNames.substring(1, allNames.length() - 1) + "!!!!!"; } /* * 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; } } }