Question: Using Stack algorithm as shown in the code above, create a program that is capable to store 10 numbers. The program should accept a number

Using Stack algorithm as shown in the code above, create a program that is capable to store 10 numbers. The program should accept a number entered from the keyboard. The user can add a number while the array is not yet full, once the array is full the program should show message that the array is full, and the user can only add another number if the user will remove a number from the array. The program should also inform the user if the array is empty.

Note: The program should have a menu as shown below and include all necessary error checking for this program.

Menu [1] Insert Number [2] Remove Number (Note: The user will enter what number to remove) [3] Display content of the array [4] Exit Enter your choice:

class StackX {

private int maxSize;

private long[] stackArray;

private int top;

public StackX(int s) {

maxSize = s;

stackArray = new long[maxSize];

top = -1;

}

public void push(long j)

{

stackArray[++top] = j;

}

public long pop()

{

return stackArray[top--]; }

public long peek()

{

return stackArray[top]; }

public boolean isEmpty()

{

return (top == -1); }

public boolean isFull()

{

return (top == maxSize-1); }

}

using this class without chinging any thing

but write the main and

the write the code remove by the user

the user get to choose what to remove from the stacl

using java eclipse

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!