View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sp01 Final Exam Review: Sensor Management System

See Final Exam Review - Sp2001

Comments? Answers? Criticisms?

a.
numbersRead _ 0.
[numbersRead < 100] whileTrue: [
command _ SensorStream next.
numbersRead _ numbersRead + 1.
(command = 0) ifTrue: [
x _ SensorStream next.
y _ SensorStream next.
str _ (Character value: (SensorStream next)) asString.
str displayAt: (x@y).
numbersRead _ numbersRead + 2.
].
].
b.
soundalarms _ Bag new.
numbersRead _ 0.
[numbersRead < 100] whileTrue:[
command _ SensorStream next.
numbersRead _ numbersRead + 1.
((command >= 1) and: [command <= 255]) ifTrue: [
soundalarms add: command.
].
((command >=256) and: [command <=511]) ifTrue: [
count _ soundalarms occurrencesOf: (command-255).
(count > 3) ifTrue: [
command inform: 'ALARM!'.
].
].
].

Doug Powers


a. "numbersRead _ numbersRead + 2." should be "3", not "2"
b. "(count > 3) ifTrue: [" should be ">=", not ">"

chok :-)


You're correct on the 3 instead of 2 thing; however I think the > is still correct since it says "more than".
Doug Powers


oops! you're right, sorry.
chok :-)


puzzeld whats a bag got to do with it

Bag has an occurencesOf: method which is very fast. If you use an OrderedCollection, instead, then occurencesOf: is linear. If you use a Set, then each number will only be stored once, which is not what we want here. -Lex Spoon


very intresting but does it work?



Link to this Page