Question: project ch12_ex3_Stack includes the following class GenericStackApp.java public class GenericStackApp { public static void main(String[] args) { } } 1. Use proper statement indentation and

 project ch12_ex3_Stack includes the following class GenericStackApp.java public class GenericStackApp {

project ch12_ex3_Stack includes the following class

GenericStackApp.java

public class GenericStackApp {

public static void main(String[] args) {

} }

1. Use proper statement indentation and meaningful variable names in the code.

2. Add a multi-line description of this application that also includes your name and the date written at the beginning of the code.

3. Add appropriate descriptive comments to each line of code you add to the project explaining why the code is in the application.

How to work with collections and gener Exercise 12-3 Create a stack this exercise, you'll create a class named Stack that uses a linked list to lement a stack, which is a collection that lets you access entries on a last-in out (LIFO) basis. Then, you'll add code to another class that uses the Stack s. The Stack class should implement these methods: Method push(element) pop() peek () size() Description Adds an element to the top of the st Returns the element at the top of the stack and removes it Returns the element at the top of the stack but does not remove it. Returns the number of elements in the stack. Create the Stack class 1. Open the project named ch12_ ex3_Stack that's in the ex_starts directory 2. Create a new class named Stack that specifies a type variable that provides for generics Declare a linked list that will hold the elements in the stack. Then, use the linked list to implement the methods shown above. 3. Add code that uses the Stack class 4. Open the StackApp class. Then, declare a generic stack at the beginning of the main() method that will store String objects. 5. Add code to the main) method that uses the pushO method to add at least three items to the stack. After each item is added, display its value at the console (you'll need to use a string literal to do this). Then, use the sizeC method to return the number of items in the stack and display that value 6. Use the peek() method to return the first item and display that item, and us 7. Use the pop() method to return each item, displaying it as it's returned, and 8. Run the project. If it works correctly, your output should look something like the size(0 method to return the number of items again and display that value. display the number of items one more time this Push: Apples Push: Oranges Push: Bananas The stack contains 3 items Peek: Bananas The stack contains 3 items Pop: Bananas Pop: Oranges Pop: Apples the stack contains 0 items

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!