Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note : Never hard - code test data in the test program, unless explicitly stated in the assignment. Always allow the user to enter the

Note : Never hard-code test data in the test program, unless explicitly stated in the assignment.
Always allow the user to enter the test data using menu option.
NO Zip files
Part 1 : Stacks
The goal of this part is to reinforce the concept of stacks and their implementation. Specifically, this part
is to implement few functions to manipulate stack objects of different types.
Design and implement the following functions in a test program in file called testStack.java:
1. Function topToButtom(...) takes a stack object of type integer and displays the stack content
from the top of the stack to the bottom of the stack. That is, the top value is printed first; while the
bottom value is printed last. This function does not change the stack content. See example
output below.
2. Function buttomToTop(...) takes a stack object of type double and displays the stack content
from the bottom of the stack to the top of the stack. That is, the bottom value is printed first; while
the top value is printed last. This function does not change the stack content. See example
output format below,
3. Function flipStack(...) takes a stack object of type string and returns the same stack object
with its content being flipped (re-arranged). That is, the stack content is changed by this function.
For example, if stack Names has the values (top to bottom): Ed, Tom, Bob, Amy before
calling this function, the stack will have the values (top to bottom): Amy, Bob, Tom, Ed after
the function is executed. See example output format below.
4. Function searchStack(...) takes 2 parameters: a stack object of type integer and an integer
target value. It returns true if the target value is on the stack at any place; otherwise it returns
false. This function does not change the stack content. See example output format below.
Write your main function (main()) as part of file testStack.java and test every function listed above.
Make your outputs clean and meaningful, and follow this sample run to format your outputs. Develop a
simple menu, below, to allow the user to select and exercise an option:
MAIN MENU
1. Test function topToButtom with integer stack
2. Test function buttonToTop with double stack
3. Test function flipStack with string stack
4. Test function searchStack with integer stack
5. Exit program
Enter option number:
Always re-display the menu after an option (other than option 5) is fully exercised with blank lines
before and after the menu.
Do Not hard-code test data in the code. Under each option, allow the user to enter the stack values.
The menu gives the user control of how to run the program and in any order they wish. Do Not use
output labels as input prompts. Test your code with the following sample inputs and format the output
as shown below. Notice how output values are lined-up after the labels.
Testing function topToButtom:
Stack content: 8875543
Function output: 3455788
Testing function buttomToTop:
Stack content: 3.54.65.59.7
Function output: 3.54.65.59.7
Testing function flipStack:
Testing function searchStack:
Stack content: 11141525716095
Target value: 88
Function output: false
Allow the user to continue to run the program until option 5 is selected (use sentinel loop concept).

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

Step: 3

blur-text-image

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago