






Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Midterm Review - Sp2001
A midterm in 2340 is 4-5 questions like each of the below. Most of the questions below are from actual midterms in CS2390 and CS2340.
I recommend working together to figure out the solutions. I will check up on the discussions, but I won't provide answers where no answers are posted.
Unless you need to edit/repair something here, do not edit this page! Put your answers on the answer page. If you do edit this page, please be careful with the formatting. Thanks! Mark Guzdial
P.S. Yes, it's true – at least one problem from the review typically appears on the actual Midterm.
Coding Sensor and Turtle
Write a piece of workspace code that:
- Waits for the user to press down and up on the left ("red") button (Hint: Sensor redButtonPressed and whileFalse: can take an empty block, e.g., [ "nothing" ])
- Draws a square of 100 pixels per side at the point where the user clicks (Sensor mousePoint) using a Pen (Hints: place: sets the Pen down at a point without drawing, down puts the Pen down, go: goes forward, turn: turns to the right). The click point should be the lower right corner of the square.
Put your answers/comments/questions at Sp2001 Midterm Review: Coding Sensor and Turtle
Dealing with the European Vacation
One of the members of a CS2340 team unfortunately missed all of the lectures on UI because of his European vacation. Heís trying to get his first MVC interface to work, and heís asking you for help. Answer his questions below.
(a) "Okay, Iíve got this Clock object, and Iíve got this ClockText thatís going to display the time. When Iím first setting up the text area, how do I tell Clock that this instance of ClockText is a view for it?"
(b) "Now, the time has changed. How does the ClockText find out that it has to display a new time?"
(c) "That seems like an awful lot of work! Why not just have the Clock display the correct time at each second? Why involve ClockText at all?!?"
Put your answers/comments/questions at Sp2001 Midterm Review: Dealing with the European Vacation
Design the ability to Phone Home
You are designing a new home entertainment center that can communicate by phone (so that you can always phone home to program the VCR to catch the big game when you have to work late).
- The Television knows its channel and its volume setting. It knows how to turn on and off, and how to set the current channel and volume, and return it.
- The SettopBox knows its Television and its ID on the CableNetwork. It can tell the TV to turn on/off, to turn the channel on the TV, and to report its ID when requested.
- The VCR knows its channel, its start record time, and its stop record time. It knows how to play, record, fast forward, rewind, set start time, set stop time, and set record channel.
- The EntertainmentPhone knows the VCR. It knows how to accept a call, and how to tell the VCR to set the record start and stop times and the record channel.
Draw the UML class diagram for this set of classes.
Put your answers/comments/questions at Sp2001 Midterm Review: Design the ability to Phone Home
Design Critique
A friend is showing you his object-oriented analysis and design. Your job is to critique it. Whatís going wrong in each of these situations?
(a) (6) "Here are my CRC cards. This class here is named MapLinkedList and it is a collection of all the Map objects in the system..."
(b) (6) "Here is my object ProcessMap. It knows its Map and it does the basic processing needed to get it on my website..."
(c) (8) "But everything is controlled here by the MapManager object. No other object processes without confirming it with the MapManager."
Put your answers/comments/questions at Sp2001 Midterm Review: Design Critique
Write Smalltalk Code
Write workspace code (something I can select and say DoIt in the workspace) to draw the below figure. (Iím not worried about sizes or exactnessódraw two rectangles with the text inside.) (To remind you, Pens know how to up, down, go:, turn:, and north:. Strings know how to asDisplayText, and a DisplayText knows how to displayAt: a given point.)

Put your answers/comments/questions at Sp2001 Midterm Review: Write Smalltalk Code
UML Class Diagramming
Draw a UML class diagram for the set of classes described below.
- A Student has a name, a student number, a major, and a transcript. A student knows how to change her major, can report her name or student number, and can provide a grade for a given course.
- A Transcript has a collection of course grades. It knows how to add a course grade, and how to look up a grade for a given course.
- A Major has a department name and a list of courses that are required. It only has accessors.
- A Course has a name, and a number of credit hours associated. It knows how to respond with its name.
- A CourseGrade has a course and a grade associated. It has accessors for each.
Put your answers/comments/questions at Sp2001 Midterm Review: UML Class Diagramming
UI Toolkit Structure
Explain how the components of MVC are reflected in Morphic by answering the below questions.
A. (5) If the controller is essentially the "event loop," where is the event loop in Morphic?
B. (10) In MVC, we have the dependency mechanism (changed:/update:) for handling the update of the view upon changes in the model. Two questions: (I) Can we use this mechanism in Morphic? (II) If we chose not to use it, is there another mechanism to insure that the views update properly?
Put your answers/comments/questions at Sp2001 Midterm Review: UI Toolkit Structure
History of Objects
A. (7) How did an early drawing tool influence object-oriented thought?
B. (8) What do simulations have to do with the creation of C++?
Put your answers/comments/questions at Sp2001 Midterm Review: History of Objects
O-O Systems
(a) What's a class? What's an instance?
(b) What's the difference between a class and instance method?
(c) What's the difference between a class and instance variable?
(d) What are the strengths and weaknesses of a prototype vs. class-based object system?
Put your answers/comments/questions at Sp2001 Midterm Review: O-O Systems
Hotel Doors OOA/D
You have been hired to design a door lock and tracking system for a hotel. These are doors that are opened with a key card that contains an encoded number of some sort. NOTE: The keys have no processor nor network connection. You can't "talk to" a key.
- Each door lock has a connection to a central lock database
- A master key should open any door.
- A customer is given one or more keys that should open the door that she is assigned to
- If a customer loses a key, all the current keys should be made invalid, and only the new keys should be accepted.
- When a customer checks out, all the current keys should be made invalid, and only the new keys should be accepted.
(a). Name at least two classes that you would need in the design for this system, and two classes that you might consider but would reject. Give your reasons for rejecting those two classes.
(b) Draw the CRC cards for this scenario:
A customer gets a card key, takes it to the door, puts it in the door lock which checks if it's valid, then the door opens because it is valid.
Put your answers/comments/questions at Sp2001 Midterm Review: Hotel Doors OOA/D
Analyze Student/Classroom Code
Imagine that I have a Student object in a Classroom object, something like this.
| s c |
c := Classroom new name: 'CS2390'.
s := Student new name: 'Fred'; section: 'a'; number: '123456789'.
c add: s.
s := Student new name: 'Wilma'; section: 'b'; number: '3456789012'.
c add: s.
s := Student new name: 'Barney'; section: 'a'; number: '012345678'.
"...More code here..."
a. (7 points) What would you say is the relationship between Student objects and the Classroom object is? Why?
b. (10 points) What attributes and services do you think that the Student and Classroom objects have, based on what you see in the above code?
Put your answers/comments/questions at Sp2001 Midterm Review: Analyze Student/Classroom Code
History of Object Systems
- What is Sketchpad?
- What is Simula?
- What do they have to do with C++?
Put your answers/comments/questions at Sp2000 Midterm Review: History of Object Systems
Short Essays
a. Explain how object-oriented programming is related to simulations.
b. What is a CRC card? What are they good for? When do you use them?
c. Explain in what sense inheritance is a form of delegation.
d. Why is it useful to think about objects as "biological cells"? (Hint: Think about scalability and about modularity.)
Put your answers/comments/questions at Sp2001 Midterm Review: Short Essays
Reading Code
| anArray aString |
anArray := #('abc' 'def' 'ghi','jkl').
aString := ''.
anArray do: [:each |
aString := aString, each.].
Transcript show: aString.
a. What appears on the Transcript ?
b. How many times did the do: loop get executed?
| i test |
i := 1.
test := (i < 10).
[test] whileTrue: [Transcript show: 'hello'.
i := i + 1.].
c. How many times does hello get printed in this example?
Put your answers/comments/questions at Sp2001 Midterm Review: Reading Code
Definitions
Define each and give an example.
a. What is Inheritance?
b. What is Delegation? How does it relate to Inheritance?
c. What is Polymorphism? How does it relate to Inheritance?
Put your answers/comments/questions at Sp2001 Midterm Review: Definitions
Drawing in Smalltalk
1.Using Pen, write the code to draw an equilateral triangle.
2.Using the Box class, write the code to draw a pyramid of three boxes.
3.Explain what this code will do:
| joe |
joe := Box new.
30 timesRepeat: [joe turn: 12.]
Put your answers/comments/questions at Sp2001 Midterm Review: Drawing in Smalltalk
Analyze Robot Car
A robot is being designed to explore the surface of Mars autonomously.

Features of this robot include:
- Six wheels A-F (three per side) which can go forward or backward independently. There is a Controller that can also activate all wheels at once.
- Two sets of sensors. Sensors can be on or off.
- An array of twelve distance sensors 1-12 around the perimeter. Distance sensors report distance to nearest obstacle in direction of sensor.
- An array of four light sensors pointed upward and outward: L3, L6, L9, and L12. Light sensors report brightness.
- A solar panel on an axis and motor capable of turning 360 degrees.
You are being asked to write some of the operating software for this robot.
Create a class diagram for the robot.
(You don't have to add more than what's in the above example.) Note: Partial credit will be given, so err on the side of too much, not too little. In your analysis, be sure to address:
- What classes do you need? What service do each need to provide? What attributes do each need to know?
- Where are there generalization-specialization relationships? Where are there part-whole relationships?
Put your answers/comments/questions at Sp2001 Midterm Review: Analyzing the Robot Car
Code for Robot Car
Code for Robot Car: Here is part of the vehicle avoidance method for the robot:
moveBackAfterBumpingFront: sensor
sensor = 11
ifTrue:
[ "Assume that we1ve bumped our front left bumper"
"Shift all wheels into reverse gear"
#('a' 'b' 'c' 'd' 'e' 'f') do: [:each | each shiftRear.]
"Activate all wheels for one second."
wheelsController activateFor: 1.
"Shift left side wheels into forward gear."
#('a' 'b' 'c') do: [:each | each shiftForward.].
"Makes left wheels go forward while right wheels go reverse -- left turn."
wheelsController activateFor: 1.
].
Write the analagous code for bumping the front right bumper.
sensor = 1 ifTrue:
[
Your code goes here
]
Put your answers/comments/questions at Sp2001 Midterm Review: Coding the Robot Car
Links to this Page
- Reviews last edited on 24 July 2007 at 2:44 pm by balladeer.cc.gatech.edu
- Jack Gruendler last edited on 17 December 2005 at 10:33 am by adsl-065-007-134-025.sip.asm.bellsouth.net
- Fall 2005 Discussion 4 last edited on 6 December 2005 at 3:45 pm by r36h51.res.gatech.edu
- Discussion 4 - David Figlar last edited on 10 October 2005 at 6:20 am by r52h163.res.gatech.edu
- Midterm Review last edited on 7 December 2005 at 10:44 pm by frankfort-win.cc.gatech.edu