ShawnStewart / java-stack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stack

Instructions

A "stack" is an abstract data type. It is a LIFO construct: Last In, First Out. Think of a stack of plates in a dining hall or restaurant's plate dispenser. The first plate gets a bunch of plates put on top of it. The last plate you put on the stack of plates is the first one you could remove.

  • Make a class called "Stack" and give it this LIFO functionality. Our Stack class's storage will be an Array with a maximum of 1000 elements of type string. You'll want to make methods
  • Print - print the items in the order they were added to the stack. Should be in the form of [‘item1’, ‘item2’]
  • Pop - Remove the last item from the stack and return the item
  • Push - Put the item on top of the stack
  • numOfItems - No items in on the stack, return the message “There are no items in your Stack, otherwise, return the number of items.

After creating the classes, have the program do the following

  • Make a new stack
  • Report number of items on the stack
  • Push first
  • Push second
  • Push third
  • Report number of items on the stack
  • Print the stack
  • Pop the stack
  • Print the stack
  • Pop the stack
  • Print the stack
  • Pop the stack
  • Print the stack
  • Report number of items on the stack

Your output should look like this:

There are no items in your Stack.

3

[ 'first', 'second', 'third' ]

[ 'first', 'second' ]

[ 'first' ]

[]

There are no items in your Stack.

About

License:MIT License