Assignment 5: Guide – SWE 619 – ALL – Spring 2010

 

Goal: Iterator / JUNIT.

 

Basic Assignment

 

For this assignment use the partial implementation of an Integer Stack below and provide an implementation of an Iterator called “StepThrough.” The Iterator should be modeled based on the pattern shown in Liskov’s book chapter 6 figure 6.8 (i.e., Java Inner Class). In addition, please provide the following:

 

·         toString method

·         reOk method

·         JUNIT test

 

Therefore, you need to submit the following:

 

·         Informal descriptions of rep invariant and abstract function (use Liskov notation)

·         StackOfInts.java – this must include the following methods: toString and reOk

·         JUNIT test

·         Test output

 

 

 

public class StackOfInts {

       

        private int[] stack;

        private int next = 0;  // index of last item in stack + 1

       

        public StackOfInts(int size) {

               //create an array large enough to hold the stack

               stack = new int[size];

        }

       

        public void push(int on) {

               if (next < stack.length)

                  stack[next++] = on;

        }

        public boolean isEmpty() {

               return (next == 0);

        }

       

        public int pop(){

               if (!isEmpty())

                   return stack[--next]; // top item on stack

               else

                  return 0;

        }

       

        public int getStackSize() {

               return next;

        }

       

        // Provide StepThrough Iterator Implemenation

       

}