public class BoxOfCandy
{
    // package access for testing
    Candy[][] box;
    
    public boolean moveCandyToFirstRow(int col)
    {
        if(box[0][col] != null)
            return true;
        
        for(int r = 1; r < box.length; r++)
        {
            if(box[r][col] != null)
            {
                box[0][col] = box[r][col];
                box[r][col] = null;
                return true;
            }
        }
        
        return false;
    }
    
    public Candy removeNextByFlavor(String flavor)
    {
        for(int r = box.length - 1; r >= 0; r--)
        {
            for(int c = 0; c < box[0].length; c++)
            {
                if(box[r][c] != null &&
                        box[r][c].getFlavor().equals(flavor))
                {
                    Candy selected = box[r][c];
                    box[r][c] = null;
                    return selected;
                }
            }
        }
        
        return null;
    }
}
