uml exercises

94
Exercises on basic UML Paolo Ciancarini

Upload: luis-carlos-murcia-bermudez

Post on 18-Apr-2015

609 views

Category:

Documents


28 download

TRANSCRIPT

Page 1: Uml Exercises

Exercises on basic UML

Paolo Ciancarini

Page 2: Uml Exercises

Summary

•  This is a set of exercises on writing and understanding the UML notations

•  Some exercises have more than one correct answer

•  Most of them are taken from the net

Page 3: Uml Exercises

Diagrams covered •  Use case diagrams •  Class diagrams •  Object diagrams •  State diagrams •  Activity diagrams •  Sequence diagrams •  Communication diagrams

Page 4: Uml Exercises

Think about it!

Page 5: Uml Exercises

On requirements

Which of these are functional requirements? a) Users of the library are either normal or staff b) A user can borrow a book c) A staff person can borrow a book d) The library contains one million books e)  If a user asks a book that has been borrowed, her

request is inserted in a waiting list f)  Staff has no priority in borrowing books

Page 6: Uml Exercises

On requirements

Which of these are non-functional requirements? a) Pressing the switch the room gets lightened b) Pressing the switch the room gets lightened in less than

one second c)  If the room is dark, pressing the switch it gets lightened d) The light in the room must be sufficient to read e)  If someone is reading then the light must stay on f)  After two minutes that the room is empty the light must

switch off

Page 7: Uml Exercises

On requirements

Which of these are functional requirements? a) A person can enroll in a course b) Only 10 persons max can enroll to this course c) A student is a person d) A course is taught by a professor e) A professor is not a student f)  Each course terminates with an exam g) Every exam produces a ranking of all participants

Page 8: Uml Exercises

On requirements

Which of these are functional requirements? The Iphone a)  can function as a camera b)  has a camera with 2.0 megapixels with geotagging c)  is a portable media player d)  offers an Internet client e)  renders a virtual keyboard by its multitouch screen f)  is connected to a PC via a USB plug g)  includes a digital compass in the 3GS model

Page 9: Uml Exercises

On requirements •  Based on the following statements from a domain expert on a project, which of the

following are requirements that must be extracted? "We get incomplete mortgage applications all the time. In those cases, we just hand them back to the customer with a handwritten note telling them what's missing. We have to log the application anyway, so we use the new mortgage screen to enter the customer information and assign a unique identifier to the file. In the past, we have entered the address in upper case. The identifier follows an industry standard format of bank number, customer account number, and the next available number for that customer all as one long number."

a)  A note must be sent to the customer for incomplete mortgage applications, listing the missing items

b)  A file must be established for every mortgage application at the time it is submitted, whether the application is complete or not

c)  Addresses on mortgage applications must be entered as all capital letters

d)  A unique mortgage number must be assigned to each mortgage file. This identifier must follow financial industry standard format

Page 10: Uml Exercises

On requirements

Which requirement has the best form? •  The system could be used to manage one or

more libraries •  The system shall manage the lending of books •  The system is initially either off or on •  The system could have several users •  The system goal should be to let users to borrow

books

Page 11: Uml Exercises

On requirements and Use Cases

•  A library is attended by readers who borrow books and staff who lend books. Both operations require user id and passwd for logging reasons

log

borrow

lend log

borrow

lend

<<Include>>

<<include>>

log borrow

lend

<<extend>>

<<extend>>

a) b)

c)

Page 12: Uml Exercises

Inventory System In order to generate an invoice a clerk must log in. If a clerk is a first time user, one must have themselves registered. There should be an option for a user to register oneself within the login page. Any user can use the system to view products online. The option of login is also provided when a user views products online.

On Use Cases diagrams Draw a use case diagram for the scenario below:

Page 13: Uml Exercises

On Use Case diagrams

Customer Service Clerk

Maintain Relationships

Order Clerk

Process Orders

CustomerMaintain Orders

SupplierMaintain Inventory

Packaging ClerkShi p Product

Bill ing Clerk

Generate Invoice

Accounting Syste m

Manager

Time

Decision Support

Which use case is not valid?

Page 14: Uml Exercises

On Use Case diagrams Identify two errors

Page 15: Uml Exercises

On Use Cases diagrams Which sentences are true for this diagram? a) There are seven actors b) There is one main actor c) There are 18 use cases d) There are 10 use cases e) DropSeminar includes Registrar f)  PostOffice extends DistributeTranscripts

Page 16: Uml Exercises

On Use Case diagrams

Which statements are true for an Actor? a) an actor is a role a user plays with respect to the

system b) an actor can be modeled as a class c) an actor generates events d) generalization is not applicable to actors e) an actor does not need to be human: a subsystem

or external system can be modelled as an actor This question has 3 correct answers.

Page 17: Uml Exercises

On Use Cases diagrams Which of these are true? a)  The diagram shows a data flow from one actor to another b)  The diagram shows an inheritance relationship between two

actors c)  The diagram shows an <<extend>> dependency between two

actors d)  Manager can use the same use cases as a Staff and one or

more additional ones e)  Staff can use the same use cases as a Manager and one or

more additional ones f)  Only Manager actors exist, as Staff is an abstract actor.

Page 18: Uml Exercises

On Use Cases diagrams

•  Is this diagram correct?

•  Is there anything missing or to add?

•  Can you provide a narrative for the diagram?

Page 19: Uml Exercises

On Use Cases diagrams When you have the final list of use cases, some questions to ask to find out if you have found them all are:

a)  Is each functional requirement in at least one use case? b)  Have I considered how each stakeholder will be using the system? c)  Have I missed any technical terms that describes the system? d)  What information will each stakeholder be providing for and

receiving from the system? e)  Have I considered the maintenance issues? f)  Have I broken the problem down into pieces that the system will

handle? g)  What information will each external system be providing to the

system and receiving from the system? h)  Have I identified all of the external systems with which the system

will need to interact?

Page 20: Uml Exercises

Reading exercises •  Read the UML class diagram •  Pay attention to the multiplicity •  Try to understand the relationship and

describe it in natural language

Page 21: Uml Exercises

Veterinary System •  Try to read & understand this UML diagram

Page 22: Uml Exercises

Veterinary System •  Read and understand this UML diagram

•  1 or more Pets associated with 1 PetOwner •  Each pet has exactly one PetOwner

Page 23: Uml Exercises

Computer System

Page 24: Uml Exercises

Computer System

•  1 CPU associated with 0 or more Controllers •  1-4 DiskDrives associated with 1 SCSIController

•  SCSIController is a (specialized) Controller

Page 25: Uml Exercises

Library System

Page 26: Uml Exercises

Library System

•  1 or more Book associated with 1 or more Pages •  Patron & Shelf use (depend on) Books

Page 27: Uml Exercises

Banking System

Page 28: Uml Exercises

Banking System

•  1 Bank associated with 0 or more Accounts •  Each Account is associated with exactly one bank

•  Checking, Savings, and MoneyMarket are Accounts

Page 29: Uml Exercises

Home Heating System

Page 30: Uml Exercises

Home Heating System

•  Room has 1 Thermostat •  Each Thermostat is associated with 0 or more Heaters

•  A Heather has exactly one Thermostat

•  ElectricHeater is a specialized Heater

•  AubeTH101D is a specialized Thermostat

Page 31: Uml Exercises

Company

•  Each employee works for one company (which can have 0 employees)

•  Each AdministrativeAssistant has one or more supervisors (who can have 0 or more employees) •  Each Company has exactly one BoardOfDirectors (and viceversa)

•  Each Office is allocated to zero or more Employees (an Employee can have no office or at most one) •  A Person is boardMember of 0 or more BoardOfDirectors (each BoardOfDirectors has from 3 to 8 Persons)

Page 32: Uml Exercises

Printing System

Page 33: Uml Exercises

Family

A woman can have as sons two twins?

Page 34: Uml Exercises

On class diagrams

•  A house may have any number of pets living in it

•  The two possible types of pets that can live in a house are dogs and cats

•  Each dog or cat has a name •  An animal’s house is its one and only

home •  You can ell an animal to make noise and it

will do its thing

Page 35: Uml Exercises
Page 36: Uml Exercises

Solution

Page 37: Uml Exercises

On class diagrams

Given that having multiple spouses at the same time is prohibited, but it is allowed to have many spouses over time …

a)  The diagram represents the concepts to be modeled and no changes are required

b)  Use the <<history>> stereotype to show the history over time and snapshot in time constraint in the model.

c)  Promote the “is married to” association to an association class called Marriage and break up the Many-to-Many association between Husband and Wife

d)  Create a link attribute called “wedding date” and attach it to the association, rather than to either Class in the Association

e)  Create a link attribute called “wedding date” and attach it to either husband or wife class

Husband Wife is married to

0..n 0..n

Page 38: Uml Exercises

On class diagrams

Which sentences are coherent with this model? a)  A company may employ 0 or 1 person b)  A person may work for a single company c)  A person has one employment d)  A company has one employer that is a person e)  A company may have zero employers

Person Company employer

* 0..1

Period

Employment

Page 39: Uml Exercises

On class diagrams

This diagram says that objects:

a) Persons have a name b) Guitarists have a name c) Guitars have a name d) MusicPlayers have a

name

Page 40: Uml Exercises

On class diagrams

This diagram describes a)  a sequence b)  a domain c)  a system d)  a use case e)  a temporal behavior

Page 41: Uml Exercises

On class diagrams

Which of the following aspects is not part of a design class diagram? a) Attributes with their types b) Operations with arguments and results c) Composition relationship d) Events and actions e) Visibility information f) Navigation information

Page 42: Uml Exercises

On class diagrams Classify the following into generalization (G), association

(A), aggregation (AG), or composition (C): a)  A country has a capital city b)  A dining philosopher uses a fork c)  A file is an ordinary file or a directory file d)  Files contain records e)  A class can have several attributes f)  A relation can be association or generalization g)  A polygon is composed of an ordered set of points h)  A person uses a computer language on a project

Page 43: Uml Exercises

On class diagrams The arrow between the two classes indicates: a)  Inheritance b) Association c) Dependency d) Sending a message

Page 44: Uml Exercises

On class diagrams

Page 45: Uml Exercises

On class diagrams

Page 46: Uml Exercises

On class diagrams

A visitor register is made of visitor entries

Page 47: Uml Exercises

On class diagrams This diagram says that objects having a “main” method are a) Persons b) Guitarists c) Guitars d) MusicPlayers, when implemented by Guitarists

Page 48: Uml Exercises

On class diagrams:

•  Right or wrong? Student

- passedModules: list of Strings

Module - name:String - code:int

Page 49: Uml Exercises

Module

- name: String

- code: int

prerequisites + equivalents

On class diagrams

•  Right or wrong?

*

Page 50: Uml Exercises

On class diagrams

Examine these two diagrams; true or false? a)  The right diagram has more information b)  The left diagram has more information c)  They are equivalent, but the right one is simpler d)  They are equivalent, but the left one is simpler

Page 51: Uml Exercises

On class diagrams

This association could be translated in an interface like: a) class Order { public OrderLine getLineItems() ;

public void addLineItem(Number amount);!b) class Order { public OrderLine getLineItems() ;

public void addLineItem(OrderLine lineItem);!c) class Order { public OrderLine getLineItems

(Product aProduct) ; public void addLineItem(Number amount, Product aProduct);!

d) class Order { public Object getLineItems() ; public void addLineItem(OrderLine lineItem); !!

Page 52: Uml Exercises

On class diagrams

Which of the following are illegal combinations of subtypes in the diagram? a)  Female, Patient, Nurse b)  Male, Physiotherapist c)  Female, Patient d)  Female, Doctor, Surgeon e)  Patient, Doctor f)  Male, Doctor, Nurse

Page 53: Uml Exercises

On class diagrams

A benefit of using polymorphism is a reduction of: a) methods in the associated classes b) subclasses needed to accomplish the same

functionality c) case statements and conditionals d) coupling between classes in the system

Page 54: Uml Exercises

On class diagrams Which sentences are true? a)  CheckingAccount implements BankAccount b)  CheckingAccount and SavingAccount are BankAccount c)  CheckingAccount and SavingAccount are associated d)  BankAccount is associated to CheckingAccount e)  SavingAccount can processCheck f)  CheckingAccount has a balance

Page 55: Uml Exercises

On object diagrams

•  This object diagram is instance of which class diagram(s)?

Car

Wheel

Engine Car

Wheel

Engine Car

Engine Wheel

Page 56: Uml Exercises

On object diagrams

This object diagram a) Includes an anonymous object b) Includes a class c)  Includes four instances d) Includes three instances

Page 57: Uml Exercises

On object diagrams

Which diagrams are correct?

Person

:John

Person

Man

Person

:John

Person

Man

a) b) c) d)

Page 58: Uml Exercises

On objects diagrams

Which one is a non valid instance of this model?

a) b)

d)

c)

Page 59: Uml Exercises

On object diagrams

•  Which is the class diagram which best corresponds to this object diagram?

Teacher Student assgnlab handinlab team

Teacher Student assgnlab handinlab team1 team2

Teacher Student assgnlab handinlab team1

team2 Teacher Student assgnlab handinlab

1 2

a)

b)

c)

d)

Page 60: Uml Exercises

On state diagrams This state diagram a) Has a superstate “student” b) Has a superstate “undergraduate”

c) Has several final states d) Has several initial states e) Describes two objects: student

and undergraduate

Page 61: Uml Exercises

On state diagrams •  Describe at least three sequences of events which

would get stuck this state diagram after 3 transitions

Page 62: Uml Exercises

On state diagrams The diagram represents a) A Document b) A Printer c) A Word-processor d) A User of a word-processor e) A Page being printed f)  The diagram is invalid

Page 63: Uml Exercises

On state diagrams What is a guard condition in a state diagram? a) An expression comparing the attributes of the modeled

objects against the attributes of the associated object. b) The condition of a person guarding the state diagram from

unwitting destruction by the collaborating designers c) A boolean expression of attribute values which allows state

transition only if condition is true d) A boolean expression that allows the transition from the

state of the current object into a state of another object in the system

e) A state activity that protects object attributes from accidental modification by unconditional actions of state transitions

Page 64: Uml Exercises

On state diagrams In a State Diagram, which of the following is true? a)  Actions are associated with a transition and are considered to

be processes that occur quickly and are not interruptible b)  Actions are associated with transition and are considered to

be processes that occur quickly and are interruptible c)  Activities are associated with states and can take longer. An

activity may be interrupted by some event d)  Activities are associated with transition that occur quickly and

are not interruptible e)  Activities are associated with states and can take longer. An

activity cannot be interrupted by any event

Page 65: Uml Exercises

On state diagrams In this diagram a)  There are no loops b)  There are five states c)  Dispatching comes after

Checking d)  Waiting is parallel to Delivered e)  There are no events f)  There are simultaneous events

Page 66: Uml Exercises

On state diagrams

•  Which condition statement? Wait

Searching

Display results

Display no matches

entry/ Display search page

entry/ Display journal list

entry/ Display NoMatch msg

[empty list]

[else]

User enters search criteria/Query db

Db returns results

Page 67: Uml Exercises

On state diagrams Which of the following statements about state

diagrams is correct? a) All actions in a state diagram are attached to

transitions b) An event may cause an object to remain in the

same state it was prior to the event c) Once an object leaves a state, it cannot return to

that state d) Two different transitions out of the same state may

overlap (they can be triggered by the same event)

Page 68: Uml Exercises

On state diagrams •  What state(s) is the object in after the following

sequence of events? •  a b c b g a

Page 69: Uml Exercises

On activity diagrams

•  Which of the following modeling elements are not found in an Activity Diagram?

a) associations b) swimlanes c) initial node, final node d) fork and join nodes

Page 70: Uml Exercises

On activity diagrams •  What is the maximum number of

concurrent threads that is possible in this activity diagram?

a)  1 b)  2 c)  3 d)  4 e)  5

Page 71: Uml Exercises

On activity diagrams In this diagram: a)  Fill Order is executed before Receive Payment b)  Overnight Delivery is executed in parallel with

Regular Delivery c)  Close Order is executed after Receive

Payment d)  Fill Order is executed in parallel with Send

Invoice e)  Send Invoice is possibly executed f)  Regular Delivery is always executed

Page 72: Uml Exercises

On activity and sequence diagrams

•  Which sequence diagram is not consistent with the activity diagram?

Page 73: Uml Exercises

On sequence diagrams

Which symbol represents a process activation? a) 1 b) 2 c) 3

1  

2  

3  

Page 74: Uml Exercises

On sequence diagrams

•  Which one of the following fragments of sequence diagram represents the action: "Object A sends to object B several messages named msg”?

a) b) c) d)

Page 75: Uml Exercises

On sequence diagrams Which symbol represents a synchronous message? a) 1 b) 2 c) 3

1  

2  

3  

Page 76: Uml Exercises

On sequence diagrams What is this in the red oval? a)  A message b)  A guard c)  An event d)  An association

Page 77: Uml Exercises

On sequence diagrams Given the sequence diagram on right, which class diagram is consistent?

Page 78: Uml Exercises

On sequence diagrams

Given the sequence diagram on right, which class diagram is consistent?

Page 79: Uml Exercises

On sequence diagrams •  What can you say about the control flow of each

of the following systems? –  Which is more centralized? –  Which is more distributed?

79

Page 80: Uml Exercises

On sequence diagrams What is wrong with this sequence diagram?

80

Page 81: Uml Exercises

On sequence diagrams What is wrong with this sequence diagram?

81

Page 82: Uml Exercises

On sequence diagrams What are the names of missing

classes XXX and YYY in the sequence diagram?

a)  XXX = DeliverySchedule,

YYY = Supplier b)  XXX = Supplier,

YYY = DeliverySchedule c)  XXX = PreferredSupplier,

YYY = DeliverySchedule d)  XXX = DeliverySchedule,

YYY = PreferredSupplier

Page 83: Uml Exercises

On communication diagrams This diagram contains a) swimlanes and temporal marks b) objects and messages c) classes and associations d) components and events

Page 84: Uml Exercises

On communication diagrams These two diagrams are equivalent or not?

Page 85: Uml Exercises

On diagrams

Which among these are behavior diagrams? a) Use case diagrams b) Class diagrams c) State diagrams d) Sequence diagrams e) Communication diagrams f)  Package diagrams g) Deployment diagrams

Page 86: Uml Exercises

On diagrams For understanding event control mechanisms, such as user interfaces and device controllers, which one of the following artifacts is the most useful?

a)  Interaction Diagrams b) Activity Diagrams c) Package Diagrams d) State Diagrams e) Class Diagrams f)  Communication diagrams g) Deployment diagrams

Page 87: Uml Exercises

On diagrams

What is the best diagram type to represent the sentence “all men are mortal”?

a)  Use case diagram b)  Class diagram c)  Object diagram d)  Activity diagram e)  Communication diagram

Mortal  

Man  

Page 88: Uml Exercises

On diagrams For the business modeling of a human organization or the workflow of a system, which one of the following artifacts is the most useful?

a)  Interaction Diagrams b) Activity Diagrams c) Package Diagrams d) State Diagrams e) Class Diagrams f)  Collaboration diagrams

Page 89: Uml Exercises

On diagrams

What are the nodes in this diagram?

a) Roles b) Actors c) Use cases d) Artifacts e) Events

Page 90: Uml Exercises

On diagrams A car has a Starter, some Lights, an AirConditioning System, some Wheels. The driver operates first the Starter, then the Lights, then the AirConditioning System, and finally the Wheels. Which pair of diagrams is most useful to model this situation? a)  Use cases and scenarios b)  Use cases and class diagrams c)  Class and sequence diagrams d)  Class and statechart diagrams e)  Class and object diagrams

Page 91: Uml Exercises

Do-it-yourself exercises Use case diagram describe how to play chess via an interface able to connect

either different engines or a chess server via internet Class diagram describe the pieces, chessboard and the game tree Object diagram describe by object snapshots a chess position during a game Activity diagram describe a game workflow including two players playing via a

(telnet) chess server Statechart describe a game workflow from the viewpoint of the chessboard Sequence diagram describe a multiagent system evaluating a position Communication diagram describe a multiagent system evaluating a position

Page 92: Uml Exercises

The UML certification by OMG

Page 93: Uml Exercises

References www.pearsonvue.com/omg/!www.objectsbydesign.com/projects/umltest/bparanj-answers-1.html!dn.codegear.com/article/31863!parlezuml.com!www.proprofs.com/quiz-school/story.php?title=quiz-uml-20!

Page 94: Uml Exercises

Think about it!