Executive Summary [Good To Go]

This is the fifth graded lab for CS2102.

1. Stated Aims

  1. Acquire experience using the java.util.ArrayList class

2. Background knowledge

  1. Understand basic concept of ArrayList from lecture
  2. Have a working knowledge of a Stack

3. Setup

If you are in the Lab, perform the routine KH 202 setup or AK 120D setup; for now, ignore the "advanced setup" options. If you would like to set up  Eclipse on your personal computer, then (a) install Java JDK 1.5 if you need to as described in tools section (here); and (b) install Eclipse as described in tools section (here).

4.1 Write a Stack using an ArrayList to store the information

Get the skeleton LabStack files within the Examples folder in Eclipse/SourceForge under the package lab5. I copy the file below for your convenience.

Create a new class LabStack that will perform as a "Last-in, First-out" stack. Imagine a stack of trays in the cafeteria. To add a try to the stack, you place it on top (an action known as push) of the stack. To remove a tray from the stack, you remove the top-most one (an action known as pop).

[wikipedia]

Your LabStack class must implement the following methods:

package lab5;

import java.util.*;

public class
LabStack {

    /** Store all information using an ArrayList. */
    ArrayList   info;

    /** Define the constructor. */
    public LabStack () {
        // Fill in here
    }

    /**
     * Determines if stack is empty.
     * @return    true if the stack contains no information; false otherwise.
     */
     public boolean
empty () {
        // Fill in here
    }

    /**
     * Add an object onto the stack so that it will become the next 'top' of the stack.
     * @param o   Object to be placed on the top of the stack.
     */
     public void
push (Object o) {
        // Fill in here
    }

    /**
     * Pop an object from the top of stack, reducing the size of the stack by one.
     * @return    Object that had been previously at the top of the stack.
     * @exception java.util.EmptyStackException    if stack had been empty.
     */
     public Object
pop () {
        // Fill in here
    }

    /**
     * Without altering the stack, return the top-most element on the stack.
     * @return    Object that is at the top of the stack.
     * @exception java.util.EmptyStackException    if stack is empty.
     */
     public
Object top () {
        // Fill in here
    }

}

4.2 Use the LabStack to perform simple Reverse Polish Notation (or postfix) computations

Once you have completed the LabStack class, then try out the simple calculator that uses LabStack, which can be found in the Eclipse/Examples directory under lab5/Calculator.java.

See if you can modify this class to support '*' (multiplication), '/' (division), and '-' (subtraction).

5. Turnin

  1. Zip up the project and submit your LabStack.java file.
Date Reason/Change
12/06/06 Final Page