Question: Java please, will leave a thumbs up for code and output. In some other applications, we might need two stacks with the same type of

Java please, will leave a thumbs up for code and output.

Java please, will leave a thumbs up for code and output. Insome other applications, we might need two stacks with the same type

In some other applications, we might need two stacks with the same type of data. If we implement the stacks as arrays, there is a chance that one array (and hence one stack) becomes filled, causing our computation to end prematurely. This might be a shame, since the other array (stack) might have plenty of room. One way around this problem is to implement two stacks as one large array rather than two smaller arrays. YOU MUST WRITE YOUR OWN STACK CLASS do not use the Java Library, Stack Class. Requirements No files are provided with any part of this Assignment. Assume you need two stacks with the same type of data. If you implement the stacks as arrays, there is a chance that one array (and hence one stack) will become filled, causing our computation to end prematurely. This might be a shame since the other array (stack) might have plenty of room. One way around this problem is to implement two stacks as one large array rather than two smaller arrays (stacks). Write a class for a pair of stacks. A pair of stacks is simply an object with two stacks. Call these stacks StackA and StackB. You need separate methods for each stack: pop_a and pop_b push_a and push_b These methods is_empty and is full only require one method for both stacks Variables will be needed to keep track of the top of each stack, call them top_a and top_b Implement the stack pair as a single array. The two stacks grow from the two ends of the array, so for example, one stack could fill up one quarter of the array, while the other fills up three quarters. Use int for the underlying type of the stack data. If the array runs out of room, print a statement to the screen that the array is full and end the program. Testing In order to test your stack pair, write the main method in the class, that will push a few values onto the Stacka then push a few values onto StackB . The program should pop the values on Stacka and check that they are correct as they are popped. The program should pop the values on stacks and check that they are correct as they are popped. HINT: 1. You can write all of this in one class file (variable declaration, constructors, methods etc) 2. Methods are contained in a class. To run a Java program, the program must have a main method (see method header below). public static void main(String args[]) The main method is the entry point where the program starts when it is executed. For this exercise, add your main method at the bottom of your class definition. 3. Review Chapter 1 Summary, Liang p. 28

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!