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. 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 is empty a and is empty b is full // you only need one is full because if there's // room in the array there's room for either a or b Variables will be needed to keep track of the top of each stack, call them topa 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please write in java. Add comments but make the comments short. No need for really long comments.  Please keep code very neat and simple , dont add anything unneccesary in the code if you weren't instructed to do so. If youve answered this before please dont copy and paste from a previous question! (Rewrite it in another way)..... Also be sure to read the instructions below carefully. The Instructions attached below will explain everything you'll be doing. NO THIS is not a homework assignment, it's practice work.  Please type the code out so that I can copy and paste it into my IDE and see the output for my self but also still provide a screenshot of your output!

### Using int for Stack Data

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

To test your stack pair, write the main method in the class, which 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 `StackB` and check that they are correct as they are popped.

**Part 1** requires user input. Input data for `StackA`, and then some for `StackB`, and then print both. Then delete something from each stack and print again.

#### HINT:

1. You can write all of this in one class file (variable declarations, constructors, methods, including main method).
2. Methods are contained in a class. To run a Java program, the program must have a main method (see method header below).
   
   ```java
   public static void main(String args[])
   ```

   The main method is the entry point where the program starts when it is executed.
Transcribed Image Text:### Using int for Stack Data 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 To test your stack pair, write the main method in the class, which 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 `StackB` and check that they are correct as they are popped. **Part 1** requires user input. Input data for `StackA`, and then some for `StackB`, and then print both. Then delete something from each stack and print again. #### HINT: 1. You can write all of this in one class file (variable declarations, constructors, methods, including main method). 2. Methods are contained in a class. To run a Java program, the program must have a main method (see method header below). ```java public static void main(String args[]) ``` The main method is the entry point where the program starts when it is executed.
In some applications, we might need two stacks with the same type of data. If we implement the stacks as arrays, one array (and hence one stack) might become filled, causing computations to end prematurely, even if the other array has space. To resolve this, implement two stacks as one large array instead of two smaller arrays.

**YOU MUST WRITE YOUR OWN Stack Class – do not use the Java Library, Stack Class.**

Assume you need two stacks with the same data type. If implemented as arrays, one might become filled prematurely, which might be a problem if the other stack has space. This issue can be resolved by implementing two stacks as one large array.

**Task:**
Write a class for a pair of stacks, an object with two stacks called StackA and StackB. Create separate methods for each stack:

- `pop_a` and `pop_b`
- `push_a` and `push_b`
- `is_empty_a` and `is_empty_b`
- `is_full` 

Only one `is_full` method is needed to check if there's room in the array for either stack.

Variables will keep track of the top of each stack, named `top_a` and `top_b`.

Implement the stack pair as a single array. The two stacks should grow from opposite ends of the array. For instance, one stack could fill one-quarter of the array, while the other fills the remaining three-quarters.
Transcribed Image Text:In some applications, we might need two stacks with the same type of data. If we implement the stacks as arrays, one array (and hence one stack) might become filled, causing computations to end prematurely, even if the other array has space. To resolve this, implement two stacks as one large array instead of two smaller arrays. **YOU MUST WRITE YOUR OWN Stack Class – do not use the Java Library, Stack Class.** Assume you need two stacks with the same data type. If implemented as arrays, one might become filled prematurely, which might be a problem if the other stack has space. This issue can be resolved by implementing two stacks as one large array. **Task:** Write a class for a pair of stacks, an object with two stacks called StackA and StackB. Create separate methods for each stack: - `pop_a` and `pop_b` - `push_a` and `push_b` - `is_empty_a` and `is_empty_b` - `is_full` Only one `is_full` method is needed to check if there's room in the array for either stack. Variables will keep track of the top of each stack, named `top_a` and `top_b`. Implement the stack pair as a single array. The two stacks should grow from opposite ends of the array. For instance, one stack could fill one-quarter of the array, while the other fills the remaining three-quarters.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education