Please implement a Pop() operation on a stack in Java. 1. The program should read in 18 different integers from a text file into a stack of type integer 2. print the contents of the stack OR print error if stack is empty 3. Pop the top element of the stack 4. and print the contents of the stack again.
My last question was not answered so I am trying again. Please solve this problem in Java. Please a create Java class that does the Pop() operation on a stack as described in the image below. The class will need to read the integers from the text file and
Text file(Stack_Ints.txt):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Sample Output:
Print: stack elements
print: Popped element
print: updated stack elements
Ans:)
For this project please follow the below instructions carefully.
There are three classes in this project.
Stack.java -> For stack implementation and its methods including pop.
Main.java -> For main implementation and execution of the program.
Integers.java -> Contain integer text file for input.
NOTE: Please put all these three files in the same package name com.Test and copy the absolute path of a text file in the Main class file field.
The working code and screenshot are given below.
The code will print the content of the stack and then pop the element until the stack is empty.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images