CS 635 Advanced Object-Oriented Programming
Spring Semester, 2005
Assignment 3
© 2005, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 4/5/05
SpreadSheet
Due April 21
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 . You should support at least the operations +, -, *, / , lg (base 2) and sin.
2. Implement a spreadsheet with 6 cells with a GUI. The cells are labeled $A, $B, $C, $D, $E and $F. A cell can contain either a formula, a number or be empty. A formula can contain numbers, reference to cells and the operations. 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. Provide the user with a button to switch between views.
View |
$A |
$B |
$C |
$D |
$E |
$F |
---|---|---|---|---|---|---|
Equation |
1 |
2 |
$A + $B |
|||
Value |
1 |
2 |
3 |
While in the value view if a user changes the value of a cell (for example cell $A) 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.
View |
$A |
$B |
$C |
$D |
$E |
$F |
---|---|---|---|---|---|---|
Equation |
1 |
$A + 1 |
$B + 1 |
$C + 1 |
$D + 1 |
$A + $E |
Value |
1 |
2 |
3 |
4 |
5 |
7 |
In this example all other cells depend on $A. If the user changes the value in cell $A 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.
View |
$A |
$B |
$C |
$D |
$E |
$F |
---|---|---|---|---|---|---|
Equation |
1 |
$A + $C |
$D + 1 |
$B * 2 |
||
Value |
1 |
Error |
Error |
Error |
You might find the observer and state patterns useful here.
Grading
Item |
Percent of Grade |
Working Code |
20% |
Unit Tests |
10% |
Proper implementation of Patterns |
60% |
Quality of Code |
10% |