This lab will help you learn about linked lists. You will also become familiar with packaging, classification, and polymorphism in Java and Object Oriented Design in general. Based on the class hierarchy built for Queue you will build a the components of the class hierarchy for Stack.
cd public-html/classes/csc241
cp -r ~mohammad/public-html/classes/csc241/Queue .
-- don't forget the dot or the -r. This command replicates my Queue directory and places it in your account.
cd Queue
javac *.java
will
compile all Java files in that directory. So, in the
Queue directories compile the .java files.
java test test.dat dynamic
java test test.dat fixed 10
You need to create the Stack directory and the four files Stack.java, fixedStack.java, dynamicStack.java, and stackException.java; then compile them. These files need to be packaged as csc241.Stack. You will also need to create the testStack directory as it exists for the Queue package as well and test to make sure your Stack classes works correctly.
Stack is the interface for stack and is
similar to the Queue interface; but its different, so be careful.
fixedStack implements the Stack
interface. You should follow the code we developed in class for
Stack of Objects.
You will need a top method as the interface calls for it; it didn't
exist in our class example. Also, keep in mind that push and
pop's return value types need to be Stack and you need to do a
return this;
in each case.
dynamicStack.java also implements the Stack interface. Following dynamicQueue works only partially in this case; pay close attention to the instructions in th eon-line documentation about this class.
stackException is thrown in the Stack interface and in classes that implement it. follow the queueException class.
test.java will be just like the test program for the queue class, except for the fact that it will be testing a stack; it needs stack's constructors and methods. Make sure that both implementations work before turning the lab in.