top of page

Download the needed files, you should have multiple .java files, LLNode,
TestLinkedStack and LinkedStack. StackInterface and the custom
exception classes.
Problem 1:
Part 1
You are required to complete the LinkedStack class, this is the class we created
earlier and you are required to complete few extra methods for this class.
For every method you have to complete, you are provided with a header, Do not
modify those headers(method name, return type or parameters). You have to
complete the body of the method.
public String toString()
The toString method should return a string representation of the stack, each
element is printed on its own line.
public int size()
returns the size of the stack.
Test your method with TestLinkedStack, complete one method at the time
and uncomment the method calls in the main method.
Part 2
Create an Interactive Test Driver(ITD) for your application.
Create a class named LinkedStackITD, the tests in this class will not be hard
coded, instead, the main method creates a LinkedStack and give the user a list
of operations they can perform on the linked stack like, push, pop, top, size,
isEmpty and toString.
In addition, add a method named clear, the method should empty stack. This
option should be added to the list of options given to the user.
Test your ITD by pushing, popping and performing other operations on the Linked
Stack, try to perform pop and top on an empty stack, and make sure it doesn’t
crash your program.
On the next page, I’m showing an example of the ITD usage. This is just an
example of how the ITD should look like.
Remember, the LinkedStackITD is a separate class you have to create, you are
free to add any methods to that class in order to create the ITD.
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 2
Empty Stack
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 3
Empty Stack
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 1
Enter your data: John
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 1
Enter your data: Sarah
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 4
Size: 2
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 6
Sarah
John
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 5
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 4
Size: 0
1-Push 2-Pop 3-Top 4-Size 5-Clear 6-Display 0-Stop
Enter your choice: 0
Bye
General Instructions:
- No hard copies will be collected.
- Do not send your files through the email!
- You should submit your work by the due date, No extensions will be given.
(See syllabus for late homework policy).
- DO NOT turn in multiple files, only one .zip file.
What to turn in:
There should be three .java files(LinkedStack.java and LinkedStackITD), put all
those files into a zip file and name it <YourFirstName_YourLastName>.zip,
submit the zip file into the Dropbox on D2L.
How to zip multiple files?
On Windows: Select all the files > right click > Send to > Comprised File
On Mac: Select all the files > Click/Tap with two fingers > Compress Items

CS304, Data Structures, Homework 4

$0.00Price
    bottom of page