Lab #10 (Exercise 11-3)
Create a stack
Due Date: Tuesday of Week 4
10 points
In this lab, you'll create a class called genericStack that uses a linked list to implement a stack, which is a collection that lets you access entries on a first-in, last-out basis. Then, you'll create another class that uses the GenericStack class. the GenericStack class should implement these methods:
Method | Description |
---|---|
push(element) | Adds an elemnt to the top of the stack. |
pop() | Returns and removes the element at the top of the stack. |
peek() | Returns but does not remove the element at the top of the stack. |
size() | Returns the number of entries in the stack. |
- Start a new class named GenericStack 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.
- Compile the class.
- Open the GenericStackApp class:
- Declare a generic stack at the beginning of the main method that will store String objects.
- Add code to the main method that uses the push 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 peek method to return the first item and display that item, and use the size method to return the nmber of items in the stack and display that value. Next, use the pop method to return each item, displaying it as it's returned. Finally, use the size method to return the number of items again and display that value.
- Compile and run the class. If it works correctly, your output should look something like shown above.
Create the GenericStack class
Create a class that uses the GenericStack class
- Name of program
- Team's name with all the names of the members (e.g. Team A: John Doe, Jane Smith, etc.)
- Current Date
- Computer system and compiler you are using
- Brief description of the program
Compile and run the Java program.
Take a screen capture by hitting simultaneously the keys Alt and Print Screen (Prt Sc) of the output results (console) and paste it in MS Paint. Save it as a gif file.
When you are ready, upload the java program and the gif file by clicking the link below:I cannot grade if I don't get the files and receive your email.