public class Pizza {
  
  /** The size of the pizza. */
  private String size;
  
  /** The toppings on the pizza. */
  private String[] toppings;
  
  /** The number of toppings currently on pizza.*/
  private int currToppings;
  
  /**
   * Create a new pizza.
   * @param s The size of the pizza.
   * @param numToppings The number of toppings
   * on the pizza.
   */
  public Pizza(String s, int numToppings) {
    size = s;
    toppings = new String[numToppings];
  }
  
  /** 
   * Add a topping to the pizza.  Return true
   * if topping was added, and false otherwise.
   */
  public boolean addTopping(String t) {
    if(currToppings < toppings.length) {
      toppings[currToppings] = t;
      currToppings++;
      return true;
    }
    return false;
  }
  
  /**
   * Remove a topping from the pizza.
   */
  public void removeTopping (String t) {
    int foundElement = -1;
    
    // find the element in the array
    for(int i = 0; i < currToppings; i++) {
      if(toppings[i].equals(t)) {
        foundElement = i;
      }
    }
    
    // fill in the space created by the null
    // element, by moving other toppings
    if(foundElement != -1) {
      toppings[foundElement] = toppings[currToppings - 1];
      toppings[currToppings - 1] = null;
      currToppings--;
    }
  }
  
  public String toString() {
    String result = "";
    for(int i = 0; i < currToppings; i++) {
      result += toppings[i] + " ";
    }
    return result;
  }
}
