
Provide a flowchart and
package arraystack;
import java.util.Scanner;
import java.util.Stack;
class ArrayStack {
public static void main(String[] args) {
int type_of_op;
Stack<String> str=new Stack<>();
Scanner s = new Scanner(System.in);
while(true) { System.out.println("*********Stack Menu*********\n"); System.out.println("Pick a number");
System.out.println("1. Push");
System.out.println("2. Pop");
System.out.println("3. Peek");
System.out.println("4. Exit");
System.out.println("\n Enter your choice \n");
type_of_op = s.nextInt();
switch (type_of_op) {
case 1: System.out.println("Enter your element which you want to push");
str.push(s.next()); System.out.println("The Stack is: " + str);
break;
case 2: str.pop(); System.out.println("The Stack is: " + str);
break;
case 3: System.out.println("Topmost element is: " + str.peek());
System.out.println("The Stack is: " + str);
break;
case 4: System.out.println("Program Exiting....");
return; default: System.out.println("You have entered a wrong choice!");
return;
}
}
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

- What is the major difference between the "Pop" and "Top" methods in the Stack implementation described in the book and slides? What would be a scenario when you might want to call "Top" rather than "Pop" and vice versa?arrow_forwardI don't get the "//To be implemented" comments, what am I supposed to do?Also, are the header files and header files implementation different? Like is the linkedList.h different than the linkedList.h (implementation)?arrow_forwardplease include a picture of the program and the output too and thank you!!!arrow_forward
- I ran the code and got an error. I even created a main.java file to run the test cases. Please fix the error and provide me the correct code for all parts. Make sure to give the screenshot of the output as well.arrow_forwardArrays in Java are objects that use reference semantics. Explain what this means and How it affects modification of arrays. You must start a thread before you can read and reply to other threadsarrow_forwardYou will create two programs. The first one will use the data structure Stack and the other program will use the data structure Queue. Keep in mind that you should already know from your video and free textbook that Java uses a LinkedList integration for Queue. Stack Program Create a deck of cards using an array (Array size 15). Each card is an object. So you will have to create a Card class that has a value (1 - 10, Jack, Queen, King, Ace) and suit (clubs, diamonds, heart, spade). You will create a stack and randomly pick a card from the deck to put be pushed onto the stack. You will repeat this 5 times. Then you will take cards off the top of the stack (pop) and reveal the values of the cards in the output. As a challenge, you may have the user guess the value and suit of the card at the bottom of the stack. Queue Program There is a new concert coming to town. This concert is popular and has a long line. The line uses the data structure Queue. The people in the line are objects…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





