Due on Wednesday,2 March 2005, by 12:00
This homework has four parts: three are technical drills and the fourth part
is the creative one. The goal is to make sure that
you know how to handle the techical details of developing and thoroughly testing
the Stack class, both yours and the one already provided by Java, and then apply it to a simple problem: Matching parentheses.
Parts I, II and III can (and should be) done before the Tuesday
class, possibly with some help from the TAs on the technical
For Part IV, you should read and understand the problem before
Tuesday's class. I will give you extra hints on it on Tuesday,
should there be a need.
To avoid naming conflicts, you
must develop each program in a separate directory.
To be started on Thursday during the lab session.
Implementation of a Stack abstract data type
Implement a class called IntStack for a stack of integers, with the following specifications:
To test the class, you will design a Java application, with a menu-based test-driver. The text-based menu asks the user
to choose an option from a list. The options correspond to the methods of the Stack class: create a new stack, test if it is empty or full,
push and pop elements, display the top element or print the whole list.
- The class is implemented as an array of integers. There must be a maximal allocated size, and an index, called top,
indicating the next available position.
- The class contains the following methods:
- Peek: returns the top element
- Print (for testing purposes)
Design a GUI test-driver for the IntStack class.
- First, extend the IntStack class to a new class called DIntStack (a "drawable" stack). This contains a new
method called Draw which displays the contents of the integer stack on a display (Graphics).
- Design an applet to test the DIntStack class. The Model will be a stack of integers, the Controller will have a button for
each method of the class, and the View will consist in drawing the stack using its Draw method.
Data Abstraction: replacing one implementation with another
In both of the previous exercises, replace the class IntStack with the Java Stack class. Compile and test each implementation.
Implement a class called Paren (from "parentheses"), which
handles correctly parenthesized expressions. Such an expression
(a "Paren") is stored as an array of characters, and manipulated
via class-specific functions. The constructor initializes an
empty Paren expression. The function Input reads in from the user
an expression and checks that it contains only the 6 types of
allowed (open and closed parentheses of three types, (),  and
The function Print prints the expression. The function Match
verifies that the expression is correct (all the parentheses match).
To test the class, you will implement a testdriver as a Java application or (for extra credit) a Java applet with a
For this homework, particular emphasis will be placed on testing,
therefore make sure you have tested ALL the functions in your
class on significant cases.
- Parts I, II and III done perfectly, will get you a grade of B+.
- To get a grade in the A category, you must do Part IV. A
working program with static testing (i.e. similar to the one
linked to from the lecture notes) is worth an A-.
For an A, you must design a better (menu-based) test-driver, which will allow
the user to choose which function to test next.
- For extra credit (A+), you should design an applet with a GUI
interface for testing the Paren class.