The user needs to create several spreadsheet objects that compute the sum of their entries, the average of their entries, and, as a special case, the sum or average of (1) the results of several spreadsheets or (2) specific cells of two spreadsheets. The user doesn't feel that they need more than single dimension spreadsheets, so cells are specified by integers. The user would like to use these spreadsheets with Workspace code that looks like this:
| ss1 ss2 ss3 ss4 ssArray| ss1 := Spreadsheet type: #sum. ss1 cell: 1 put: 15. "Puts 15 into cell 1" ss1 cell: 2 put: 30. ss1 cell: 3 put: 75.2. Transcript cr; show: ss1 value printstring. "Prints the sum (120.2) to the Transcript" Transcript cr; show: (ss1 cell: 1) printstring. "Prints 15 to the Transcript" ss2 := Spreadsheet type: #average. ss2 cells: #(24 76.4 19 37 89). "Fill five cells of the spreadsheets with these values" Transcript cr; show: ss2 value printstring. "Prints the average (49.08) to the Transcript" "Create a spreadsheet that sums the values of two Spreadsheets" ssArray := Array with: ss1 with: ss2. ss3 := Spreadsheet type: #sum with: ssArray. Transcript cr; show: ss3 value printstring. "Prints the sum 120.2 + 49.08 to the Transcript" ss1 cell: 4 put: 89.9. "Add a fourth cell to ss1." Transcript cr; show: ss3 value printstring. "Prints the updated values of ss1 and ss2" "Create a fourth spreadsheet whose value is the average of ss1 cell 2 and ss2 cell 3" ss4 := Spreadsheet type: #average with: ss1 cell: 2 with: ss2 cell: 3. Transcript cr; show: ss4 value printstring. "Prints the average of 30 and 19 (24.5)"
Special notes to consider when designing and implementing the SpreadsheetRow class.
type:with:) do not have to respond to cell messages (e.g., cell:put: or cell:).
type:with: can accept any number of spreadsheets in the array argument.
type:with:cell:with:cell: will always reference exactly two spreadsheet cells.
Spreadsheet as the entrypoint into your systems. For example, ss1 doesn't have to be an instance of class Spreadsheet. The class method type: could always return an instance of another class. (But you would not be graded down for doing so, as long as your OOA is reasonable.)
#sum and #average. (And these would be good topics to address in the Reuse section of your report!)
The user is pretty comfortable entering Smalltalk code, so it's okay to always use cell:at: and cells: messages for entering values into cells. However, the user does want to see:
In the above example, the user would expect to see a window for each of the four spreadsheets. The window should open with the same message that created the spreadsheet (e.g., type: or type:with: or type:with:cell:with:cell:). To do the windows, you will need the User interface package.