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

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:


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).

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.)

Uploaded Image: cs2340.gif

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.

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.

(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



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.

External Image

Features of this robot include:


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:


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