Advanced Java

profiletapaswini
Assignment12.docx

Assignment:

Write a program to ask the user to enter the size of the Stack after that display that Stack, after displaying that Stack you have to create a method: “public static int menu()”. That gives the 4 choices to user which should be:

1. Enter 1 to add element in Stack.

2. Enter 2 to pop the element from Stack.

3. Enter 3 to Find the Top value in the Stack.

4. Enter 4 to exit.

You have to execute each choice at least once and all this process will work in a loop after selecting any choice again your program will ask for the next step and only after entering 4 your program will be terminated.

For Example:

Please set the size of Stack at initial level.:3

Please enter the element: jay

Please enter the element: john

Please enter the element: 23

[jay, john, 23]

1. Enter 1 to add element in Stack.:

2. Enter 2 to pop the element from Stack.:

3. Enter 3 to Find the Top value in the Stack.:

4. Enter 4 to exit.:

Enter your choice.

1

Please enter the location of element: 1

Please enter the value of element: sagar

[jay, sagar, john, 23]

1. Enter 1 to add element in Stack.:

2. Enter 2 to pop the element from Stack.:

3. Enter 3 to Find the Top value in the Stack.:

4. Enter 4 to exit.:

Enter your choice.

2

Last element was removed.

[jay, sagar, john]

1. Enter 1 to add element in Stack.:

2. Enter 2 to pop the element from Stack.:

3. Enter 3 to Find the Top value in the Stack.:

4. Enter 4 to exit.:

Enter your choice.

3

The top element in the Stack is: john

1. Enter 1 to add element in Stack.:

2. Enter 2 to pop the element from Stack.:

3. Enter 3 to Find the Top value in the Stack.:

4. Enter 4 to exit.:

Enter your choice.

4

GOOD BYE!!!

Process finished with exit code 0