CSC 241- Lab 3 (Due October 17, 2003)


Theme ...

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.


Create directories and copy some files

  1. cd public-html/classes/csc241
  2. 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

    Compile Java files and run the test programs

    1. Use javac to compile each of the above .java files. In any directory, javac *.java will compile all Java files in that directory. So, in the Queue directories compile the .java files.
    2. Run the program that tests Queue.
      • Change to directory public-html/classes/csc241/Queue/testQueue
      • test.java is designed to test both the dynamic and the fixed array versions of our Queue class. I have designed it to use command line parameters for giving the data file name and other information. So, type the following to first test the dynamic version and then the fixed versions.
        1. java test test.dat dynamic
        2. java test test.dat fixed 10
    3. Make the Queue directory and all .class files in it public.

    Create the Stack class hierarchy

    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.


    What to Turn In

    Stack.java, fixedStack.java, dynamicStack.java, stackException.java, and test.java (for stacks).