Skip to main content
added 36 characters in body
Source Link
Sleiman Jneidi
  • 3.3k
  • 12
  • 20

Few comments:

  • The name StackMethods is not the best name for this, you should rather pick a name that describes your entity, eg: Stack

  • Your class only works for integers, where Stack is an ADT that should accept various types, so consider using generics instead

     class Stack<T>{ private T[] stackArray; } 
  • the fields : size, and stack have package access, and this means classes within the same package can modify them, declare them as private instead.

  • You should throw an unchecked exception in push method if the stack is full rather than printing something to the console

Few comments:

  • The name StackMethods is not the best name for this, you should rather pick a name that describes your entity, eg: Stack

  • Your class only works for integers, where Stack is an ADT that should accept various types, so consider using generics instead

     class Stack<T>{ private T[] stackArray; } 
  • the fields : size, and stack have package access, and this means classes within the same package can modify them

  • You should throw an unchecked exception in push method if the stack is full rather than printing something to the console

Few comments:

  • The name StackMethods is not the best name for this, you should rather pick a name that describes your entity, eg: Stack

  • Your class only works for integers, where Stack is an ADT that should accept various types, so consider using generics instead

     class Stack<T>{ private T[] stackArray; } 
  • the fields : size, and stack have package access, and this means classes within the same package can modify them, declare them as private instead.

  • You should throw an unchecked exception in push method if the stack is full rather than printing something to the console

Source Link
Sleiman Jneidi
  • 3.3k
  • 12
  • 20

Few comments:

  • The name StackMethods is not the best name for this, you should rather pick a name that describes your entity, eg: Stack

  • Your class only works for integers, where Stack is an ADT that should accept various types, so consider using generics instead

     class Stack<T>{ private T[] stackArray; } 
  • the fields : size, and stack have package access, and this means classes within the same package can modify them

  • You should throw an unchecked exception in push method if the stack is full rather than printing something to the console