Question: We will implement a program that will use STACK to do the add, and multiplication. (Do not use the build in function or classes of

We will implement a program that will use STACK to do the add, and multiplication. (Do not use the build in function or classes of Java or from the textbook).

You need to create Stack ADT, you may use linkedlist or array in the stack ADT.

Create a stack ADT that takes integer (INTGER Class), should include but not limited to these methods:

Constructor - Optional

push - public void push(int element) : Add the elements to the stack

pop - public int pop()

size - public int size() : returns the size of the linked list, if empty, return 0

toString - public String toString() : ToString method will override ToString method to return string containing the LinkedList elements (ready to be printed)

Now we need to test it:

Create a main that ask user to input commands.

You need to use scanner class,

Need to make sure user knows when the program starts

Need to show available commands

Available commands from command line should be:

a : It will push a value into stack. example: a 10

p : Pop

+ : Adding last two item in the stack, if empty do nothing (This method should pop the stack)

* : Multiply last two item in the stack, if empty do nothing (This method should pop the stack)

? : Prints the stack

Z : Exit the code

For this part, you do not need to make sure user input the right value and types (no expectation or defensive coding is needed)

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!