tangara goh wrote:I am puzzled about the capacity that part.
If there is no capacity stated in the constructor, how will the stack know that it's full ?
But there IS a capacity set in the constructor, and the stack DOES know that it's full, by calling the
isFull() method. It's really the same as the first two solutions.
The difference is that when the stack is full, you don't throw an exception and you don't return false, but instead you increase the capacity by creating a new larger array, and then copying the existing elements to the larger array.
How much larger? That's up to you, but it's convention to just double the size of the previous array.
Or this class is a 'utility' class that is to be made use of with other List like ArrayList, LinkedList, or Tree(am not sure about this one as I haven't go deep into it yet)
No. It's meant to use an array, not a
List. Using a
List instead of an array is what I would normally recommend, but it defeats the purpose of the assignment, which is to teach you how to do it with an array.
And using a
List will not make your class a 'Utility class'. That means something completely different.