Creating Stacks and Queues (JAVA)

A stack is a data structure that operates on the LIFO principle (last in, first out). You can think of a stack as a stack of weights where the weight on the bottom was placed there first, but all of the weights on top of it must be removed before it can be moved.
A queue is a data structure that operates on the FIFO principle (first in, first out). You can think of a queue as a checkout line at the store. Shoppers enter the queue at the end of the line and then progress until they are at the beginning of the line, where they then check out and leave the queue.
Create a stack class for integers:
Within the stack class, store up to thirty integers.
Include a push method that adds an integer to the stack.
Include a pop method that removes an integer from the stack.
When an integer is popped, use it's position in the stack for the next push.
Include an isFull method that checks to see if the stack is full.
Include an isEmpty method that checks to see if the stack is empty.
Include an output method to display the contents of the stack in LIFO order (the last number pushed should be the first number displayed). Include a message with the display stating what is being displayed.
Display the stack on one line with spaces between the numbers.
Create a queue class for integers:
Within the queue class, store up to thirty integers.
Include a push method that adds an integer to the queue.
Include a pop method that removes an integer from the queue.
When an integer is popped, reorder the queue so that the second integer is now the first, etc. and the last used position will be the next one pushed onto.
Include an isFull method that checks to see if the queue is full.
Include an isEmpty method that checks to see if the queue is empty.
Include an output method to display the contents of the queue in FIFO order (the first number pushed should be the first number displayed). Include a message with the display stating what is being displayed. Display the queue on one line with spaces between the numbers.
Create a demo class that contains the main method:
Create a stack object and a queue object.
Inside a loop, create a menu for the user. The choices are:
-1. Add a number to the stack.
-2. Remove a number from the stack.
-3. Display the stack.
-4. Add a number to the queue.
-5. Remove a number from the queue.
-6. Display the queue.
-7. Quit.
If the user chooses options 1 or 4:
-Check to see if the chosen data structure is full. If it is, display a polite message stating so and display the contents of the chosen data structure.
-If it is not full, push a random number between 1 and 100 (use Math.random()) onto the chosen data structure and display the number being pushed and the contents of the chosen data structure.
-Loop back to the menu.
If the user chooses options 2 or 5:
-Check to see if the chosen data structure is empty. If it is, display a polite message stating so.
-If it is not empty, pop a number off of the chosen data structure and display the number being popped and the remaining contents of the chosen data structure.
-Loop back to the menu.
If the user chooses options 3 or 6 then display the contents of the chosen data structure and loop back to the menu.
If the user chooses option 7 then exit the loop.
Powered by