CS 112
Homework 5

Due on Wednesday,2 March 2005, by 12:00 a.m. (midnight)


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 aspects. 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.

Part I

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.

Part II

Design a GUI test-driver for the IntStack class.

Part III

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.

Part IV

Matching parentheses

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 characters 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 GUI interface.

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.

Grading guidelines

Ileana Streinu