Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: Name of the method Possible* signature of the method Explanation Example Constructor Optional push public void push(int element) Add the elements to the stack pop public int pop() Refer to the notes 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 For this part, you do not need to make sure user input the right value and types (no expectation or defensive coding is needed) This is how your main should look like: Commands Explanation Example a It will push a value into stack 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 Welcome to Stacks! - List of command - Enter (a) to the above question and enter an integer you wish to add to your stack - Enter (+ or *) as an operator to be applied to the last two items added to your stack - Enter (?) if you wish to see everything in your stack printed to the screen - Enter (p) if you wish to remove the last item - Enter (z) if you are done playing with stacks Would you like to command: a 22 Your value has been added to the stack! Would you like to command: a 23 Your value has been added to the stack! Would you like to command: a 19 Your value has been added to the stack! Would you like to command: a 15 Your value has been added to the stack! Would you like to command: A 34 Your value has been added to the stack! Would you like to command: ? Your stack items are: [34-15-19-23-22-] Would you like to command: + You have added the last two items in your stack and pushed the total: 49 Would you like to command: ? Your stack items are: [49-19-23-22] Would you like to command: * You have multiplied the last two items in your stack and pushed the total: 931 Would you like to command: ? Your stack items are: [931-23-22] Would you like to command: z Thanks for playing

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics Of A Networked World Semantics For Grid Databases First International Ifip Conference Icsnw 2004 Paris France June 2004 Revised Selected Papers Lncs 3226

Authors: Mokrane Bouzeghoub ,Carole Goble ,Vipul Kashyap ,Stefano Spaccapietra

2004 Edition

3540236090, 978-3540236092

More Books

Students also viewed these Databases questions