Lab 7: Stacks
Due Date and Submission Requirements
- Due Date: Thursday, October 19th at 11:59 p.m.
- Partner Information: This is an individual assignment. You are allowed to collaborate with other students, but each student must submit their individual, independent solution.
- Submission Instructions: Submit your solution, StackArray.java to the appropriate D2L dropbox.
The goal of this lab is:
- Gain experience using a Stack data structure
- Implement a stack in Java using an Array
Directions
Using Lab7Demo.java as a starting point, you will define the StackArray class and fill in the missing methods for the stack data structure.
Your Stack will hold strings (you should NOT define another class, such as a Book class), and must use an array to hold its data . You can assume the stack will need to hold up to 10 elements.
You are NOT allowed to modify the Lab7Demo class. After creating the StackArray class, you must define the following methods:
- push(String newElement)- This push() method adds a new string (newElement) to the top of the stack.
- pop()- the pop() method removes and returns the top element of the stack
- peek()- the peek() method returns the current top element of the stack
- getSize()- returns the current size of the stack
- isEmpty()- returns true of the stack is empty, returns false if the stack is not empty
- printStack() - prints out each element in the stack. The top of the stack is the first thing printed out, the bottom of the stack is the last thing printed out.
Starting Code
Output
When you run your program, your output should look exactly like this screenshot
Grading (10 points)
- 2 points- push() is correct
- 2 points- pop() is correct
- 1 point- peek() is correct
- 1 point- getSize() is correct
- 1 point- isEmpty() is correct
- 1 point- printStack() is correct
- 2 points- The StackArray class is correctly defined, and uses an array