Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Writing Code (1 point)
Implement a method in Squeak that will give you the nth Fibonacci number. For both 0 and 1, the Fibonacci number equals 1. From then on, the next in the series is simply the sum of the previous two in the series (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc.). Return an error when applicable. Your code should be based on good OO-style and be an efficient algorithm.
As a suggestion, write the code in Squeak. Then, once you have debugged it, you can post it to the CoWeb by surrounding it with
(aNumber < 0) ifTrue: [self error: 'Invalid Input'].
(aNumber = 0) ifTrue: [^1].
(aNumber = 1) ifTrue: [^1].
(aNumber > 1) ifTrue: [^(self fib: (aNumber - 2) + self fib: (aNumber - 1))].
Tracing Code (1 point)
The following code solves the rainfall problem, which you may have seen in previous CS classes. For each line, describe what the Smalltalk code does. Be as specific as possible. In particular, what is data at the various points in the code?
1 | data onlyPositiveNumbers |
2 data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2).
3 onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]].
4 data := data select: onlyPositiveNumbers.
5 data := data copyUpTo: 999. "not including"
6 Transcript show: data average
Line 1: Creates two temporary variables, data and onlyPositiveNumbers, that are to be used in this method.
Line 2: Sets data equal to a newly created OrderCollection of (1 2 3 -4 -5 'error' 6 -7 999 2).
Line 3: Sets onlyPositiveNumbers equal to a block of code that acts as a filter to go through and keep only the positive numbers.
Line 4: data is rewriten to be equal to data with onlyPositiveNumbers filter applied. data now has an OrderedCollection of (1 2 3 6 999 2).
Line 5: data is now rewriten to be equal to data with the values upto 999. data now has an OrderedCollection of (1 2 3 6).
Line 6: calls the display function to display in the transcript the return value of data average, which is the average of (1 2 3 6) = 3.
CoWeb Assignment 2
Step by Step walkthrough for Monticello.
To open Monticello, in squeak (for Windows) left click in blank space to bring up the world menu.
Slect open. On the open menu go down and click Monticello Browser.
This should bring up the Monticello Browser.
You need to add both the packages and a repository before you can share any code.
To add a package click on the "+Package" button and type the package name and click accept. You should now see the package in the left textbox.
To add a repository click on the "+Repository" button and then select the type of repository you would like to set up. Our group had an ftp repository, you just fill in the url, username and password leaving the rest as is.
After you have a package to share and a repository added you highlight the package you wish to save and the repository you wish to share your code on and click the save button. You are then asked to fill in a simple explaination of what changes you made. After that is done and you click accept the code should now be on your repository for your group.
There does come times when two member are working on the same package at the same time and one of those group members sumbits his changes before you. In this case you need to merge the two together to form a new one. You do this by;
From the Monticello Browser highlight the repository the code is at then click the open button.
From the you should now be able to see all of the past code you have sumbited, now highlight the code you wish to merge with and click the merge button.
Its that easy.
To check out new code from Monticello, you simply (from the Monticello Browser) highlight the repository and click open, then highlight the code you wish to check out and click load. Stuff should happen and you should now have all of the code loacted in the saved file.
In my experience Monticello is one of the easys ways to share code in a group, plus its built into squeak.
Link to this Page