Review

Exam Description

My exams tend to have three to six questions. They are closed book, closed notes. I prefer to ask questions with objective answers. Mainly, I will ask you to draw diagrams and write Java code (although no GUIs). You will have the entire class period to finish the exam. The exam will emphasize the material covered since the last exam. The exam questions are mostly based on the homework and the lecture notes.

Study Suggestions

There are three levels of understanding. From lowest to highest they are:

Level 1: Able to understand explanations of others
Level 2: Able to solve new problems
Level 3: Able to explain material to others

You need to attain level 2 in order to pass the exam. This means you have read and understood your notes, reviewed your homework, and reviewed previous exams (level 1).

Beyond that, you have invented and solved variations of the problems discussed in class. (Level 2).

To attain Level 3, form a study group and take turns explaining the material to each other. If someone in the group gives a lazy or bad explanation, let him have it!

I tend to give away a lot of information in the review session.

Topics and Sample Questions

Basic Domain Modeling

Translate the following domain descriptions into UML class diagrams, then to Java class declarations:

1. Plays are performed in a theater. There are two types of plays: tragedies and comedies. A play has many roles. Roles are played by actors.

2.

class A { ... }
class B { ... }
class C extends A {
   B[] bees = new B[4];
}

3. There are two types of agents: diplomats and translators. An agent can send a message to another agent. In addition, translators can translate messages while diplomats can create messages.

Using the class diagrams above, translate the following scenarios into object diagrams, then translate into a Java main() method:

1. Macbeth, a tragedy, is being performed at the Globe Theater. The role of Duncan will be played by Jim Carey.

2. A Chinese diplomat sends a message, m, to a translator t1, who translates it into French and sends it to translator t2. This translator translates m from French to English and sends it to an American diplomat. Draw a sequence diagram assuming synchronous message passing.

Advanced Domain Modeling

Translate the following domain descriptions into UML class diagrams, use types as objects and association classes where it seems vaguely appropriate, then to Java class declarations:

1. A map consists of many cities. An important relationship is:

City X is N miles from City Y

2. A zoo contains many types of animals: penguins, elephants, wolves, etc. Zoo keeper X cares for animal Y for N years. The types of animals changes frequently, so representing species as classes might be a bad idea.

Using the class diagrams above, translate the following scenarios into object diagrams, then translate into a Java main() method:

   Zoo keeper smith has cared for Heckel the magpie for 5 years. He has cared for Jeckel the magpie for 3 years, and he has cared for Opus the penguin for 2 years.

Advanced Java

1. Finish this implementation:

class Interpreter {
   Object call(Class c, Method m, Object[] args) {
      // return object.m(args)
   }
}

Analysis Patterns (ontologies)

Draw object diagrams that model the following domains/scenarios. Use combinations of the analysis patterns developed in class: Actor-Role, Affiliation, Accountability, Observation, Quantity, Accounting and Inventory, Planning and Action.

1. Kiljoy, a census worker, observes that Sandoz is a 42 year old Hispanic.

2. Acme corporation is divided into two divisions: Marketing and Development. The Currently, the development division is divided into three teams: Project X team, Project Y team, and Project Z team.

3. Smith is the President of Acme. Jones and Wong are the Vice Presidents of the Marketing and Development Divisions, respectively. Marley is the chief of the Project X team. Lewis is a programmer working on Project X.

Design Patterns

You should be able to design applications by composing the design patterns covered in class. Your design will be in the form of UML class, object, and sequence diagrams. In some cases you may be asked to sketch an implementation of part of your application.

Here are some sample patterns you should know (unless they weren't mentioned in lecture):

Publisher-Subscriber
Model-View-Controller
Resource Manager
View Handler (resource manager for views)
Command Processor

Composite
Master-Slave
Abstract Factory Method (a.k.a. Virtual Constructor)

Object-as-State
Strategy
Adapter
Decorator
Proxy (decorators for remote servers)

1. A spreadsheet is a collection of cells indexed by unique names (for example A1, C3, etc.) A cell encapsulates a value of type double, which users may set or get. Additionally, the value of a cell, C, may be a sum of the values of other cells. In this case we say that C depends on these other cells. Of course when any of the cells C depends on are updated, then C must be updated, too.

Of course the spread sheet needs a user interface, too. Typically, the UI consists of a variety of controllers that process user input (menus, toolbars, dialogs) and a variety of views that display the spreadsheet (worksheet view, bar graph view, pie chart view, etc.)

Draw a UML class diagram showing how you would design a spreadsheet.

2. A popular computer game allows a player to navigate the game's hero through a series of places in an alien world. In each place the hero encounters various aliens. An alien may be friendly toward the hero, hostile, or duplicitous (seems friendly but is actually hostile). Worse, an alien may actually change his strategy for interacting with the hero in mid-game!

The places the hero travels through all offer basic services:

interface Place {
   void enter(Hero h); // what happens when the hero enters a place
   void display();
   void add(Alien a);
   void exit(Hero h);
}

A basic implementation if this interface is provided:

class EmptyPlace implements Place {
   List aliens = new LinkedList();
   void enter(Hero h) {
      // h may now move about this place
   }
   void add(Alien a) { aliens.add(a); }
   void display() {
      // display an empty room
   }
   void exit(Hero h) {
      // h exits
   }
}
     

Of course different places may want to add different behavior to each of these methods.

Draw a UML class diagram modeling the alien world. Consider using the strategy pattern for aliens and the decorator pattern for places.

Use Case Models

Draw use case diagrams for the following systems:

1. An account management system (eg. Quacken)

2. Email clients (e.g., pine, elm, mail, Netscape Inbox, Eudora, Outlook) allow users to log onto and off of SMTP, POP, and IMAP servers. Users may download email messages from their POP or IMAP servers. The downloaded messages are stored in a local mailbox. Messages can be moved to other mailboxes. (For example, Eudora mailboxes include In, Out, and Trash. Of course users can create other mailboxes.

A user can search a local mailbox in various ways (search subject, body, and from). A user can sort a mailbox in various ways (by date, sender, subject). A user can select a message from the local mailbox. A user can display, forward, reply to (/all), print, save, or delete a selected message. Additionally, a user can compose a new email message. The new message is sent by uploading it to the user's SMTP server.

Email clients also maintain an address book containing email addresses of regular correspondents. Users can add or delete addresses from the address book. Users can search the address book in various ways.

3. A web browser (eg. IE or Netscape)

4. Virtual Parlor (VP) is a chat room. Anyone with a VP client program can connect to a VP server program and begin chatting with other participants. A participant may ask to see the recent contributions of the other participants, or the participant may contribute a message to the chat room.

5. An appointment organizer.

6. A watch.

Use Case Elaborations

Finite State Machines

Use Finite State Machine models (or Activity Diagrams) to model the following systems/workflows:

1. The Admissions Office at a large university employs the following informal workflow. When a student's application is complete, one copy goes to the Financial Aid Office. In Financial Aid, the student's residency is determined by checking his residence, driver's license, tax form, and voter registration. If any one of these is from out of state, the student is classified as an out of state student. Whether the student is classified as in state or out of state, the Financial Aid office also determines if the student is eligible for a scholarship or loan.

Another copy of the student's application goes to the evaluation office. First the transcript is evaluated, then the SAT scores. The Evaluation Office employs a complicated formula. If the applicant's GPA is below 2.8, then he is rejected, unless his SAT is above 700. If his SAT is below 500 he is rejected, unless his GPA is above 3.7.

Finally, a student is sent one of four form letters: a rejection, an acceptance together with an offer of a scholarship, an acceptance together with an explanation of why the student is considered to be out of state, or an ordinary acceptance.

2. The MY Windows Operating System allows users to create windows. A window can be in one of four states: minimized, maximized, closed, or resizable. The user is provided with commands for changing the state of a window from any state to any other state, although once the window is closed, it disappears from the desktop. When a window is first created, it is created in its resizable state. This state contains three micro states: big, medium, and small, as well as a single command called resize that allows users to cycle between these micro states.

3. The Mimex company wants to develop an inexpensive watch similar to Casio and Timex watches. The Mimex watch has four buttons: set, mode, hour, and minute. It also has three modes: TIME, ALARM, BEEPING. In the TIME mode the user can display and set the time. In the ALARM mode the user can set and arm the alarm. In the BEEPING mode the watch makes a loud beeping noise. The mode button allows users to toggle between the TIME and ALARM mode. It also allows the user to move from the BEEPING mode to the DISPLAY mode. The watch enters the BEEPING mode in case of errors or in case the alarm is armed and the indicated time interval has elapsed.

In the ALARM mode consists of three micro states: SET, ARMED, DISARMED. The set button allows the user to cycle through these micro states. In the SET state the hour and minute buttons can be used to set the hour and minute the alarm should sound.

The TIME mode consists of two micro modes: DISPLAY and SET. The set button toggles between these two states. In the SET mode, the hour and minute buttons can be used to set the time.

Of course micro modes don't necessarily correspond to micro states, since the watch can be in the DISPLAY micro mode and either armed or disarmed.

4. A Blackjack dealer's workflow is as follows: shuffle the deck, wait for bets to be placed, deal two cards to each player, deal two cards to self. Each player may ask the dealer for another card. This repeats until the player says enough, or until the total points in the player's hand exceeds 21, in which case the player immediately loses his bet. Finally, the dealer gives himself extra cards until the value of his hand is 17 or higher. If his hand exceeds 21 points, he loses and pays all remaining players. Otherwise, he pays all players whose point values are higher than the dealers.