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:

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:

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.

  1. Below, write the corrected version of the connect: networkConnection to: phoneNumber method.

  2. 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?

  3. 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:

dinosaur picture

In the below short answers, I expect to see the following terms used:

Describe the relationship between:

  1. The Dinosaur and DinoParts classes.
  2. The Plateosaur and Raptor classes.
  3. The Dinosaur and Raptor classes.
  4. 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.
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:

Robot picture

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:

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
  1. What is wheelsController in the above example? Is it a class? A local variable? How do you know?

  2. What is each in the above example?

  3. 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:

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:

Post comments, discussion, answers in CaMILE at Whiz-O Toys Collaboration Space


Vending Machine CodeBelow is one method from the Vending Machine simulation.
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