CS 635 Advanced ObjectOriented Programming
Spring Semester, 2007
Assignment 4
© 2007, All Rights Reserved, SDSU & Roger Whitney
San Diego State University  This page last updated 4/10/07
SpreadSheet
Due May 1
1. Use the Interpreter pattern to evaluate postfix expressions. The expression (1 + 2) * sin(3) will be 1 2 + 3 sin * in postfix. For more information about postfix see the Wikipedia entry entry or this lecture by Bob Brown . The reason for using postfix expressions is to make it easier to parse the expression. Postfix notation is not related to the Interpreter pattern. You can restrict your values to integers if you like. You should support at least the operations +, , *, / , lg (base 2) and cos. Expressions can have variables. You can assume that all variables are uppercase and start with the character $. So ($A + $B) / $A + 2 is a valid expression which is $A $B + $A / 2 + in postfix. In order to evaluate the expression one also needs the values of $A and $B.
2. Implement a spreadsheet with 6 cells with a GUI. The cells are labeled AA, AB, AC, BA, BB and BC. We will use the symbol $AA to represent the current value of cell AA. A cell can contain either a formula, a number or be empty. A formula can contain numbers, reference to cells and the operations. The spreadsheet has two different views or modes: value and equation. The user can toggle between the two views. Provide the user with a button to switch between views. All cells are in the same mode. Either all are in the value mode or view or all are in the equation mode. In the value mode a cell displays nothing if the cell is empty, the number if the cell contains a number and the value of its equation if it contains an equation. In the equation mode a cell displays nothing if the cell is empty, the number if the cell contains a number and the source of the equation if it contains an equation.
In the In the first example below cell $A contains 1, $B contains the number 2 and cell contains the formula $A + $B. We have an equation and a value view of the cells. The table below shows both the equation and the value views of the cells.
Equation View
A 
B 
C 


A 
1 
2 
$AA $AB + 
B 
Value View
A 
B 
C 


A 
1 
2 
3 
B 
While in the value view if a user changes the value of a cell (for example cell $AA) then all cells dependent on that cell needs to be updated automatically. Note that more than one cell may require updating. The following example illustrates this.
Equation View
A 
B 
C 


A 
1 
$AA 1 + 
$AA $AB + 
B 
$AB 1 + 
$AC 1 + 
$BB $AC + 
In this example all other cells depend on cell AA. If the user changes the value in cell AA all the values in the other cells need to be updated. Note that which cells depend on which cell is completely determined by the user. You have to be careful with circular dependancies. The following is just one example of a circular dependancy. These are error conditions.
Equation View
A 
B 
C 


A 
1 
$AA $AC + 
$BC 1 + 
B 
$AB 1 + 
Value View
A 
B 
C 


A 
1 
Error 
Error 
B 
Error 
You might find the observer and state patterns useful here.
Grading
Item 
Percent of Grade 
Working Code 
10% 
Unit Tests 
10% 
Proper implementation of Patterns 
65% 
Quality of Code 
15% 
Note that while assignment uses a GUI it is not about building a fancy GUI. The assignment is about using patterns. In particular is it about the patterns used in the nonGUI part of the program.