My code is giving me problems can't add items to may stack Array Here is the code i have written

public class MyStringArrayStack implements InterfaceStringCollection {
    public String[] stackArray = new String[0];
    public int top;
    public int newSize;


    public boolean setMaxSize(int newSize) {
        if(newSize <= 0){
        return false;}
        else{ 
            top = -1;
        stackArray = new String[newSize];
        return true;
    }
    }

    public boolean add(String newItem){
        int r=0;

        if(top < (newSize-1)){
            stackArray[++top] = newItem;
            r=0;}
            //return(true);}

        else if (  (newSize-1) == top ){
            r=1; }
           // return(false);
        return (r==0);

       }


       public void clear(){   
           top=-1;

          }


       public boolean contains(String name){
           int i= 0;
            for(int z=top;z ==0;z--){
                if ( stackArray[z].equals(name)){

                    i++;
                }

            } 
           return i>0;
       }

       public boolean isEmpty(){
         return(top==-1);
       } 

       public boolean isFull(){
           if(newSize-1 == top)
               return true;
           else
               return false;
       }

      public String remove(){
          if(top > 0){
            String d = stackArray[top--];
            top --;
            return d;
          }
          else{
              return null;
          }

      }

      public boolean remove(String item){
            int t = 0; 
            for (int i=0; i < stackArray.length; i++) {
                stackArray[i - t] = stackArray[i];
                if(stackArray[i].equals(item)) {
                    t++;
     }
  }
            for (int j = 0; j < t; j++)
                stackArray[stackArray.length - (j + 1)] = null;
            return (t>0);
}


       public String getItemAt(int i){
           String a = null;
           if (top>=i){
                a = stackArray[i];
           }
           return a;

       }

       public boolean updateItemAt(int i, String item){
           if(i>top){
               return false;
               }
               else{
           stackArray[(i-1)]= item;
           return true;

       }
       }
    public int size() {
        return top;
    }

    public String[] toArray() {
        return stackArray;
    }

    @Override
    public String toString(){
        String s = "[";  
            for(int i = 0; i <top; i++){  
                s = s +stackArray[i];// [value1,value2,....] 
                    if(i<top-1)
                    {
                        s += ", "; 
                    }

    }  
                    s +="]";  
                    return s;  
    }

    public boolean addAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
            return false;
            else{

            String stackArrayCollection[];
            stackArrayCollection = new String[otherCollection.toArray().length];
            stackArrayCollection = otherCollection.toArray();
            boolean rsslt = true;
            if(stackArrayCollection.length <= (stackArray.length - top))
            {
                for(int u = 0; u < stackArrayCollection.length; u++)
                {
                    add(stackArrayCollection[u]);
                    rsslt = true;
                }
            }
            else
            rsslt = false;
            return rsslt;}
    }

    public boolean containsAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
            return false;
            else
            {
            String stackArrayCollection[];
            stackArrayCollection = new String[otherCollection.toArray().length];
            stackArrayCollection = otherCollection.toArray();
            {
                for(int v = 0; v < stackArrayCollection.length; v++)

                {
                    contains(stackArrayCollection[v]);
                    return true;
                }


                    return false;

            }
            }
    }

    public boolean removeAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
            return false;
            else
            {

            String stackArrayCollection[];
            stackArrayCollection = new String[otherCollection.toArray().length];
            stackArrayCollection = otherCollection.toArray();
            {
                    for(int p = 0; p < stackArrayCollection.length; p++)
                    {
                        remove(stackArrayCollection[p]);
                        return true;
                    }
                    return false;
                }
            }
    }


}

revise your post and put your code inside the (code) brackets availiable. it will help with clarity.

Ok sorry

public class MyStringArrayStack implements InterfaceStringCollection {
    public String[] stackArray = new String[0];
    public int top;
    public int newSize;


    public boolean setMaxSize(int newSize) {
        if(newSize <= 0){
        return false;}
        else{ 
            top = -1;
        stackArray = new String[newSize];
        return true;
    }
    }

    public boolean add(String newItem){
        int r=0;

        if(top < (newSize-1)){
            stackArray[++top] = newItem;
            r=0;}
            //return(true);}

        else if (  (newSize-1) == top ){
            r=1; }
           // return(false);
        return (r==0);

       }


       public void clear(){   
           top=-1;

          }


       public boolean contains(String name){
           int i= 0;
            for(int z=top;z ==0;z--){
                if ( stackArray[z].equals(name)){

                    i++;
                }

            } 
           return i>0;
       }

       public boolean isEmpty(){
         return(top==-1);
       } 

       public boolean isFull(){
           if(newSize-1 == top)
               return true;
           else
               return false;
       }

      public String remove(){
          if(top > 0){
            String d = stackArray[top--];
            top --;
            return d;
          }
          else{
              return null;
          }

      }

      public boolean remove(String item){
            int t = 0; 
            for (int i=0; i < stackArray.length; i++) {
                stackArray[i - t] = stackArray[i];
                if(stackArray[i].equals(item)) {
                    t++;
     }
  }
            for (int j = 0; j < t; j++)
                stackArray[stackArray.length - (j + 1)] = null;
            return (t>0);
}


       public String getItemAt(int i){
           String a = null;
           if (top>=i){
                a = stackArray[i];
           }
           return a;

       }

       public boolean updateItemAt(int i, String item){
           if(i>top){
               return false;
               }
               else{
           stackArray[(i-1)]= item;
           return true;

       }
       }
    public int size() {
        return top;
    }

    public String[] toArray() {
        return stackArray;
    }

    @Override
    public String toString(){
        String s = "[";  
            for(int i = 0; i <top; i++){  
                s = s +stackArray[i];// [value1,value2,....] 
                    if(i<top-1)
                    {
                        s += ", "; 
                    }

    }  
                    s +="]";  
                    return s;  
    }

    public boolean addAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
            return false;
            else{

            String stackArrayCollection[];
            stackArrayCollection = new String[otherCollection.toArray().length];
            stackArrayCollection = otherCollection.toArray();
            boolean rsslt = true;
            if(stackArrayCollection.length <= (stackArray.length - top))
            {
                for(int u = 0; u < stackArrayCollection.length; u++)
                {
                    add(stackArrayCollection[u]);
                    rsslt = true;
                }
            }
            else
            rsslt = false;
            return rsslt;}
    }

    public boolean containsAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
            return false;
            else
            {
            String stackArrayCollection[];
            stackArrayCollection = new String[otherCollection.toArray().length];
            stackArrayCollection = otherCollection.toArray();
            {
                for(int v = 0; v < stackArrayCollection.length; v++)

                {
                    contains(stackArrayCollection[v]);
                    return true;
                }


                    return false;

            }
            }
    }

    public boolean removeAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
            return false;
            else
            {

            String stackArrayCollection[];
            stackArrayCollection = new String[otherCollection.toArray().length];
            stackArrayCollection = otherCollection.toArray();
            {
                    for(int p = 0; p < stackArrayCollection.length; p++)
                    {
                        remove(stackArrayCollection[p]);
                        return true;
                    }
                    return false;
                }
            }
    }


}
public class MyStringArrayStack implements InterfaceStringCollection {
    public String[] stackArray = new String[0];
    public int top;
    public int newSize;
    

    public boolean setMaxSize(int newSize) {
        if(newSize <= 0){
		return false;}
        else{ 
            top = -1;
        stackArray = new String[newSize];
		return true;
    }
    }
			
    public boolean add(String newItem){
        int r=0;
    
        if(top < (newSize-1)){
            stackArray[++top] = newItem;
            r=0;}
            //return(true);}
            
        else if (  (newSize-1) == top ){
            r=1; }
           // return(false);
        return (r==0);
        
       }
       
   
       public void clear(){   
           top=-1;
              
          }
         
       
       public boolean contains(String name){
           int i= 0;
            for(int z=top;z ==0;z--){
                if ( stackArray[z].equals(name)){
                    
                    i++;
                }
                
            } 
           return i>0;
       }
       
       public boolean isEmpty(){
         return(top==-1);
       } 
         
       public boolean isFull(){
           if(newSize-1 == top)
               return true;
           else
               return false;
       }
       
      public String remove(){
          if(top > 0){
            String d = stackArray[top--];
            top --;
            return d;
          }
          else{
              return null;
          }
         
      }

      public boolean remove(String item){
            int t = 0; 
            for (int i=0; i < stackArray.length; i++) {
                stackArray[i - t] = stackArray[i];
                if(stackArray[i].equals(item)) {
                    t++;
	 }
  }
            for (int j = 0; j < t; j++)
                stackArray[stackArray.length - (j + 1)] = null;
            return (t>0);
}
      
       
       public String getItemAt(int i){
           String a = null;
           if (top>=i){
                a = stackArray[i];
           }
           return a;
       
       }
       
       public boolean updateItemAt(int i, String item){
           if(i>top){
               return false;
               }
               else{
           stackArray[(i-1)]= item;
           return true;
           
       }
       }
    public int size() {
        return top;
    }

    public String[] toArray() {
        return stackArray;
    }

    @Override
    public String toString(){
        String s = "[";  
            for(int i = 0; i <top; i++){  
                s = s +stackArray[i];// [value1,value2,....] 
                    if(i<top-1)
                    {
                        s += ", "; 
                    }
                    
	}  
                    s +="]";  
                    return s;  
    }

    public boolean addAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
			return false;
			else{
				
			String stackArrayCollection[];
			stackArrayCollection = new String[otherCollection.toArray().length];
			stackArrayCollection = otherCollection.toArray();
			boolean rsslt = true;
			if(stackArrayCollection.length <= (stackArray.length - top))
			{
				for(int u = 0; u < stackArrayCollection.length; u++)
				{
					add(stackArrayCollection[u]);
					rsslt = true;
				}
			}
			else
			rsslt = false;
			return rsslt;}
    }

    public boolean containsAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
			return false;
			else
			{
			String stackArrayCollection[];
			stackArrayCollection = new String[otherCollection.toArray().length];
			stackArrayCollection = otherCollection.toArray();
			{
				for(int v = 0; v < stackArrayCollection.length; v++)
				
				{
					contains(stackArrayCollection[v]);
					return true;
				}
			
				
					return false;
							
			}
			}
    }

    public boolean removeAll(InterfaceStringCollection otherCollection) {
        if(otherCollection.isEmpty())
			return false;
			else
			{
			
			String stackArrayCollection[];
			stackArrayCollection = new String[otherCollection.toArray().length];
			stackArrayCollection = otherCollection.toArray();
			{
					for(int p = 0; p < stackArrayCollection.length; p++)
					{
						remove(stackArrayCollection[p]);
						return true;
					}
					return false;
				}
			}
    }
       
         
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.