Midterm Review
Midterm Review, CS2390 Spring 1997
Typically, a midterm in 2390 is 4-5 questions like each of the below. Most of the questions below are from actual midterms in 2390. I recommend working together through the CaMILE links (MidTerm Review Collaboration Space)to figure out the solutions. I will check up on the discussions, but I won't provide answers where no answers are posted.
Designing a Corporate Phone System You have taken a job with the prestigious WMEP (We Make Expensive Phones) Inc. You have been asked to design the classes need in a new corporate phone system. The features needed in this new phone system are:
- Each employee has a phone with a unique number.
- There is one central switchboard. When a call comes in to the central switchboard, the switchboard polls the phones to determine which has the right number for the given call. The central switchboard then gives the network connection to the right phone, which causes the phone to ring.
- Each phone should support speed-dialing for ten numbers (the digits 0-9).
- Each employee belongs to a workgroup, and there is one designated workgroup phone in the group. If the phone rings for more than five times, the call should transfer to the workgroup phone for a central staff member to take the call.
Draw the Coad & Nicola diagram (or just answer the below questions) for this class structure below (or on the back of this page.)
(You don't have to add more features than what's described.) 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?
Post comments, discussion, answers in CaMILE at Design Phone System Collaboration Space
Fixing the Calling System An engineer who never took this class has written the method for calling a phone from the central switchboard to look like this:
connect: networkConnection to: phoneNumber
| rightPhone |
myPhones do: [:phone |
(phone phoneNumber) = phoneNumber
ifTrue: [rightPhone := each]
].
rightPhone ringWith: networkConnection.
There is a big problem with this code. If no phoneNumber matches with a phone in the central switchboard, the programmer was supposed to use the central switchboard method bounceBackToCentralOffice: networkConnection to tell the phone company's central office switch that it misrouted the number.
- Below, write the corrected version of the
connect: networkConnection to: phoneNumber method.
- Imagine that you named a class
Phone. Would Smalltalk get confused between the class Phone and the variable phone in the above method? Why or why not?
- The method above uses
= to check the phone number. What's the difference between = and ==? Would this method work if we used == instead?
Post comments, discussion, answers in CaMILE at Fixing Phone Code Collaboration Space
Dinosaur Relations The WhizO Toy Company is working
on their first video game: A fighting game with dinosaurs. The
figure below shows the result of their object-oriented analysis
of the problem:

In the below short answers, I expect to see the following terms used:
- Class
- Subclass
- Concrete and Abstract class
- Inheritance
- Gen-spec relationship
- Whole-part relationship
Describe the relationship between:
- The Dinosaur and DinoParts classes.
- The Plateosaur and Raptor classes.
- The Dinosaur and Raptor classes.
- The size instance variable in the Dinosaur class, in the Plateosaur class, and in the Legs class.
Post comments, discussion, answers in CaMILE at Dinosaur Relations Collaboration Space
Dinosaur Code Below is the Smalltalk instance method which appears in the Dinosaur class:
attack: target
| location |
location := target position.
self aim: position.
self useWeapon.
This code might be used like this:
| aRaptor aPtero |
aRaptor := Raptor new.
aPtero := Pterodactyl new.
aRaptor attack: aPtero.
- What is location?
- What is target?
- What is position? Where is position defined?
- Assuming that the system was implemented as described in the OOA diagram presented earlier, could this code work? Explain why not, or explain what assumptions you need to make.
Post comments, discussion, answers in CaMILE at Dinosaur Code Collaboration Space
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 Coad & Nicola graphical analysis 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?
Post comments, discussion, answers in CaMILE at Analyze Robot Car Collaboration Space
Code for Robot CarHere is part of the vehicle avoidance method for the robot:
moveBackAfterBumpingFront: sensor
sensor = 11
ifTrue:
[ "Assume that we've 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
]
Post comments, discussion, answers in CaMILE at Code for Robot Car Collaboration Space
Short Answers on Robot Car
- What is wheelsController in the above example? Is it a class? A local variable? How do you know?
- What is each in the above example?
- What is the difference between an instance of a class and the class itself?
Post comments, discussion, answers in CaMILE at Short Answers on Robot Car Collaboration Space
Sensor on Robot CarThe solar panel needs to turn dependent on where the light is brightest. If sensor L12 is the brightest, then the solar panel motor should turn to 0 degrees. If L3 is brightest, then the solar panel motor should turn to 90 degrees. If L6, then turn to 180 degrees. If L9, turn to 270 degrees. There is a solar panel instance method brightestSensor that returns 3, 6, 9, or 12 to indicate the brightest sensor. Assume that the solar panel has an instance variable motor which is the motor controlling the solar panel, and that the solar panel motor has a method turnTo: which takes a numeric argument for what degree heading to turn the solar panel to.
Write the solar panel instance method turnToLight.
Post comments, discussion, answers in CaMILE at Sensor on Robot Car Collaboration Space
Defining Terms Be able to explain the all-caps words in the following contexts:
- Ascii Count is a SPECIALIZATION (SUBCLASS) of Count (SUPERCLASS), which means that it INHERITS the structure and behavior of Count.
- Count is an ABSTRACT CLASS.
- A CountViewContainer sends messages to a particular INSTANCE of IntegerCount.
- Interfaces in Smalltalk are constructed from MODEL, VIEW, and CONTROLLER classes.
Post comments, discussion, answers in CaMILE at Defining Terms Collaboration Space
Whiz-O Toys You are a consultant to the WhizO Toy Company ("Makers of toys for tots of all ages"). WhizO is considering a shift to an object-oriented software development process. If they do make such a shift, you're in for big bucks as the consultant who leads the way. First step is to respond to the specific concerns of the Manager of their Software Development unit:
- "We usually have multiple teams of developers working on different parts of the programs at once. How does object-orientation help us with that?"
- "We rely heavily on simulation when developing sophisticated toys. What would be absolutely perfect would be if we could take parts of our simulation and use it in the code for the real toy. Can we do that? How?"
- "What happens if we develop add-ons for a toy, like a new Laser Gun for our Omega Video Game System? Or if we develop a new variation on a toy, like the Phaser Range Finder Gun (which is like the Laser Gun)? Can O-O help our productivity in doing this?"
Post comments, discussion, answers in CaMILE at Whiz-O Toys Collaboration Space
Vending Machine CodeBelow is one method from the Vending Machine simulation.
- To what class does this code belong? What does it do?
- Write a brief comment describing what each line of this code does.
dispense: itemToDispense
self isEmpty ifTrue: [^false].
(self itemIsDispensable: itemToDispense) ifFalse:
[^false].
self printItem: itemToDispense .
self activateDispenser.
self disconnectWithItem: itemToDispense.
^true
Post comments, discussion, answers in CaMILE at Vending Machine Code Collaboration Space
News Page | CS2390 Sum'97 Home Page | MMC-CaMILE | STABLE
Questions/comments/concerns to guzdial@cc.gatech.edu
Page last updated 7/15/97; 10:15:41 AM