public class Pizza {
  
  /** The toppings on a pizza. */
  private String[] toppings;
  
  /** The size of the pizza. */
  private String size;
  
  /** The current number of toppings. */
  private int currToppings;
  
  /** Create a new pizza with n toppings of size s. */
  public Pizza(int n, String s){   
    this.size = s;
    this.toppings = new String[n];
  }
  
  /** 
   * Add topping t to the pizza. Return true if the
   * topping was added to the pizza, and return false
   * otherwise.
   */
  public boolean addTopping(String t) {
    if (currToppings < toppings.length) {
      this.toppings[currToppings] = t;
      this.currToppings++;
      return true;
    } else {
      return false;
    }
  }
  
  /** 
   * Remove topping t from the pizza.
   */
  public void removeTopping(String t) { 
    int index = -1;
    
    // find the location of the topping
    for (int i = 0; i < currToppings && index == -1; i++) {
      if (toppings[i].equals(t)) {
        index = i;
      }
    }
    
    if (index != -1) {
      // remove topping
      // toppings[index] = null;
      this.currToppings--;
      
      // fill the hole (move null to the end)
      toppings[index] = toppings[currToppings];
      toppings[currToppings] = null;
    }
    
  }

  /**
   * Return the String representation of this pizza.
   */
  public String toString() {
    String temp = "A " + size + " pizza with the following toppings:";
    
    for (int i = 0; i < currToppings; i++) {
      temp += "\n" + this.toppings[i];
    }
    
    return temp;
  }

}

