CSCI 151 Lab 5: Stacks of Integers


Overview

In this lab, we will write two implementations of a stack and test them with JUnit.

Materials

Setup

  1. Download the skeleton for this project.
  2. Unpack the code into a new Eclipse Java project.

Description

We are discussing the Stack interface in class. To help us visualize our implementations, you will find the StackViewer class in the numstack package, written using JavaFX. Run this program to see a text box for entry and a listing below of the current contents of the stack.

Currently, the StackViewer does not work, because it is missing a stack implementation. You must implement two versions of a stack, one using an array, and the second using a list of nodes.

Step 1 - ArrayIntStack

In the numstack.model package, you will find the following classes:

IntStack.java

This is a general interface for a stack of integers. You will want to call the default method notEmpty() at the right places, to ensure the appropriate methods fail when necessary.

ArrayIntStack.java

You will use an array of integers to implement a stack. As discussed in class, you should use either Vector or ArrayList to implement ArrayIntStack.

IntStackTest.java

These are the unit tests for your stack. Your grade depends on passing these tests.

ArrayIntStackTest.java

Run this file to see the results of the unit tests for your ArrayIntStack implementation.

Step 2 - ListIntStack

You will first need to create a file called ListIntNode.java that implements the Node class we discussed. It should have an int value, and a ListIntNode next reference as components.

ListIntStack.java

You will use a sequence of ListIntNode objects to implement a stack.

ListIntStackTest.java

Run this file to see the results of the unit tests for your ListIntStack implementation.

Step 3 - TimeTest

TimeTest.java

Run this file to compare the performance of ArrayIntStack and ListIntStack.

What to Hand In

Submit your ArrayIntStack.java and ListIntStack.java implementations, along with any additional files you created for your implementations.

Grading


© Mark Goadrich, Hendrix College