Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Midterm Review - Fall 2002
A midterm in CS2340 is typically 4-5 questions like each of the below. Most of the questions below are from actual midterms. I won't post answers, but I will correct any mistakes I notice. If you don't post, I won't post.
You're welcome to post answers, questions about the answers, critiques or questions about answers that are already posted, etc.
In the third Clock user interface, a Clock instance forms the model and a ClockText instance forms a view. Describe the sequence of messages that occur when a second of time passes by, such that the Clock is updated and the updated time is displayed by the ClockText. Hints: Think about self changed:, nextSecond, update:, and dependents.
Put your answers/comment/questions at Fall2002 Midterm Review: Changed/Update mechanism
Present at the Creation?
For each of the below object-oriented ideas, where did they first come from?
a. Changing a master object and automatically updating instances of that master.
b. Defining behavior in one place for a whole group of other objects, each with its own data.
Put your answers/comment/questions at Fall2002 Midterm Review: Present at the Creation?
Simulating the Rubber Ducky!
Each year, some little towns have rubber ducky races. Each participant purchases a rubber duck that has a number on it, with the proceeds typically going to some charity. The ducks are placed in lanes at the head of a river. When the lanes are opened, the ducks are off! The river currents will sweep forward the ducks in some lanes faster than ducks in other lanes, of course. Obstacles, like rocks, in a current will bump ducks into other currents.
You, being an intense competitor and a master hacker, have decided to simulate your local town’s race in order to optimize your duck’s performance. Make the assumption that all currents are in a linear (i.e., they travel in a straight line from a given lane to the finish line) at a set speed, and that obstacles in a current bump ducks randomly to one of the neighboring currents.
Write a UML class diagram for the objects needed to construct this simulation.
[For purposes of this review discussion, just name and describe the classes that you would draw.
Put your answers/comment/questions at Fall2002 Midterm Review: Simulating the Rubber Ducky
Get the story right!
a. Most people claim that Alan Kay invented object-oriented programming with Smalltalk. Some people claim that Bjarne Stroustrup did, with C++. But a few sticklers say that both of them were influenced by the real first object-oriented programming language. What language would that be, and how did it influence both of these pioneers?
b. Object-oriented programming, overlapping windows, pop-up menus, and even much of multimedia computing today was invented by a group at Xerox PARC—whose goal was not to build the world’s first object-oriented programming language or any of the rest of that. Rather, these accomplishments were stepstones toward the bigger goal…which was?
Put your answers/comment/questions at Fall2002 Midterm Review: Get the story right!
The Big Barn
You are designing the game system that lies behind “The Big Barn,?the new attraction at Stone Mountain Park. (This is a real thing, and the below is a reasonably close approximation to how the barn works. You are being asked to come up with a design for such a system.)
- As children and families enter the Barn, they are given a bracelet encoded with a unique ID number. At the RegistrationDesk, their name is associated with the ID number in a Player object.
- As players play games around the Barn, they place their bracelets on the GameConsoles which associate points with that ID number.
- When players place their bracelets on special ScoreKiosks, then all their game points are collected and associated with their name.
- The grand ScoreBoard at the front of the Barn lists the names and scores of the current top six players.
Draw a UML class diagram for this set of classes. Hint: You are not limited to the classes identified above! You may find that you need a couple more classes.
Answer the below questions, to explain your UML class diagram:
A. Where are game points before they are associated with Players?
B. How do game points get collected by ScoreKiosks?
C. How does the ScoreBoard get the Players and determine the top six Players?
Put your answers/comment/questions at Fall2002 Midterm Review: The Big Barn
Write a method findPalindrome: that takes as input a collection of strings, possible containing spaces, (e.g. #(?002?‘a man a plan a canal panama?‘george of the jungle?) and returns just those strings that are palindromes, i.e., without spaces, the letters are the same forward and backward (for the example, #(?002?‘a man a plan a canal panama? would be the correct return value). Some useful tips:
- Strings understand reverse
- string reject: [:ch | ch = Character space] will return string with spaces removed.
Put your answers/comment/questions at Fall2002 Midterm Review: Palindromes
What’s wrong with this picture?
a. The below class diagram for a course registration system exemplifies a typical object-oriented design flaw. What is it?
Missing File (/cs2340/uploads/studentUML.jpg)
b. You’re reviewing a set of CRC Cards for a fellow object-oriented designer who’s working on an inventory control system. You see the classes: Item, WarehouseLocation, LinkedListOfShelves, Supplier, Shipper. What do you immediately point out as a flaw in his cards?
c. You’re working with a new designer with whom you’re brainstorming candidate class names. He says, “Let’s include Date and Time cards, because they’re already in Squeak, so we’ll already have those implemented.? What mistake is being made?
d. There once was a city where the payroll system was designed in-house as an object-oriented system. At first, they just had hourly employees. Later, they had crossing guards, who sometimes were volunteers. Later they added salaried employees who received a weekly pay. They never redesigned their object system, and just kept adding on to it. What flaws (there are at least two) do you see in the below object system?
Missing File (/cs2340/uploads/employeeUML.jpg)
Put your answers/comment/questions at Fall2002 Midterm Review: What's wrong with this picture?
String to Hex
Write a method stringToHex: that takes as input a string of positive integers separated by spaces (e.g. ?2 13 14? and returns a collection of the hexadecimal equivalents of each of the numbers in the string (e.g., an OrderedCollection('16rC' '16rD' '16rE')). Hints: Strings understand findTokens: which inputs a string of delimeters (e.g., ??to specify a space) and returns a collection of strings that were separated by any of those delimeters (e.g., (?2??3??3?. Hint2: Integers understand hex. Hint3: Strings understand asNumber.
Put your answers/comment/questions at Fall2002 Midterm Review: String to Hex
Help the MVC Novice
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. (4) "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. (5) "Now, the time has changed. How does the ClockText find out that it has to display a new time?"
c. (6) "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/comment/questions at Fall2002 Midterm Review: Help the MVC Novice
Design the Game
You are designing a strategy game around the marketing and signing of sports figures.
- There are athletes, who know their agents and their home team. They have a name, a salary, and a salary that they really want. They can negotiate with a team.
- There are agents, who know their athletes and the league. They have a name and a set of contracts with each athlete which describes the percentage that they get from the athlete’s contract. They also know how to negotiate and how to make secret alliances with a team or a coach.
- The league knows all the teams, and can add or remove teams. It can also impose or remove rules on how teams behave.
- Teams know their athletes, and they can negotiate and make secret deals with other teams.
- Coaches know their teams, and they can also have agents. Coaches have a name and a salary, too.
Draw the UML class diagram for this set of classes. Hint: You are not limited to the classes identified above! You may find that you need a couple more classes, particularly a superclass or two, that helps to organize this set.
Put your answers/comment/questions at Fall2002 Midterm Review: Design the Game
- Who first used the word "object-oriented" to talk about programming systems?
- How is the development of C++ and Smalltalk similar? Different?
- How did ideas in a drawing program influence OO development?
- Name another programming approach that was popular when OO was first developing, and name a language of the time that exemplified it.
Put your answers/comment/questions at Fall2002 Midterm Review: Historical Context
- What is a class? What is an instance?
- What is the difference between a class and instance method?
- What is the difference between a class and instance variable?
Put your answers/comments/questions at Fall2002 Midterm Review: OO Theory
A friend is designing a problem for his job, and they have asked you to critique it. What's going wrong in each of the following situations?
- "Here are my CRC cards. This class here is named MapLinkedList and it is a collection of all the Map objects in the system..."
- "Here is my object ProcessMap. It knows its Map and it does the basic processing needed to get it on my website..."
- "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 Fall2002 Midterm Review: Design Critique
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.
- 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.
- On the back of this sheet or on a separate sheet that you attach to the exam (remember, each problem will be graded separately!), 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 Fall2002 Midterm Review: Hotel Doors OOA/D
Write Smalltalk Code
Write workspace code (something I can select and say DoIt in the workspace) to draw the below figure. Don't worry about exact sizes–just draw two rectangles with the text inside. (To remind you, Pens know how to up, down, go:, turn:, and north:. Strings know how to displayAt: a given point.)
Put your answers/comments/questions at Fall2002 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 agrade associated. It has accessors for each.
Put your answers/comments/questions at Fall2002 Midterm Review: UML Class Diagramming
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 addStudent: s.
s := Student new name: 'Wilma'; section: 'b'; number: '3456789012'.
c addStudent: 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 Fall2002 Midterm Review: Analyze Student/Classroom Code
| anArray aString |
anArray := #('abc' 'def' 'ghi','jkl').
aString := ''.
anArray do: [:each |
aString := aString, each.].
Transcript show: aString.
- What appears on the Transcript ?
- How many times did the body of the do: loop get executed?
| i test |
i := 1.
test := (i < 10).
[test] whileTrue: [Transcript show: 'hello'.
i := i + 1.].
- How many times does hello get printed in this example?
Put your answers/comments/questions at Fall2002 Midterm Review: Reading Code
Simulate a Motorcycle
Imagine an object-oriented simulation of a motorcycle.
- When the key is inserted into the ignition, the
key object tells the
engine object to
- The engine should then start to run. When the
engine object is running, it prints Putt! to the
Transcript once a second.
- Each time the
engine objects "putts," it sends a message to its
wheel object to
- When a
wheel object turns, it prints Turn! to the Transcript.
- What instance variables are you going to need for each of the key, engine, and wheel classes?
- Write the methods insert for key; start and run for engine; and turn for the wheel.
- Write whatever accessor methods you need to make the above example work.
- Write the workspace code that you'd use to create the above scenario
Put your answers/comments/questions at Fall2002 Midterm Review: Simulate a Motorcycle
More Drawing in Smalltalk
- Using Pen, write the code to draw an equilateral triangle.
- Using the Box class, write the code to draw a pyramid of three boxes.
- Explain what this code will do:
| joe |
joe := Box new.
30 timesRepeat: [joe turn: 12.]
Put your answers/comments/questions at Fall2002 Midterm Review: More Drawing in Smalltalk
Explaining the Booms
(This problem is actually harder than I'd put on a midterm, but thinking through the issues are reasonable for the midterm)
Smalltalk provides a huge amount of flexibility...and a huge amount of danger. For each of the situations below, explain what you think will happen after it. "Smalltalk goes boom" is obvious and incomplete. Think carefully about how the system might react.
- Smalltalk := nil.
- You redefine class SmallInteger's method for "+" in a way that's correct but different than what's currently in the system.
- You set Box's superclass to nil, then execute Joe := Box new.
Put your answers/comment/questions at Fall2002 Midterm Review: Explaining the Booms
Links to this Page