ICM – Computer Science Major – Software Engineering - Part 1: Introduction and M1 Cyber Physical and Social Systems – Course unit on CPS2 engineering and development, Part 3: System Engineering
Institut Henri Fayol - MINES Saint-Étienne
Tutorial on Unified Modeling Language (UML)
This page contains a set of exercises to practice software modelling using the Unified Modeling Language (UML).
A smart lock device: UML Use Case diagram
A smart lock is an electromechanical lock which is designed to perform locking and unlocking operations on a door when it receives such instructions from an authorized device using a wireless protocol and a cryptographic key to execute the authorization process. It also monitors access and sends alerts for the different events it monitors and some other critical events related to the status of the device. Smart locks can be considered part of a smart home. [Source: wikipedia]
We consider three systems: a smart phone application, a smart lock embedded software, and the smart home platform.
-
Identify the actors.
-
Identify use cases and draw the corresponding use case diagram. Don’t try to be exhaustive, instead, try to use appropriately the different elements of the UML use case diagrams.
-
Give a textual description for each use case, stating the nominal scenario and the main use cases of anomalies and errors and their treatments. Several templates exist for expressing a use case. Each use case must have at least the following parts covered:
-
Title
-
Precondition
-
Primary Actor
-
Main Success Scenario
-
Extensions - possible alternatives of the main success scenario
-
|
Note
|
we are asking for textual use case descriptions. All use cases must have the same type of template. |
|
Note
|
Not only humans can be actors. |
Car repair and maintenance business: UML Use Case and communication diagram
The actors of a car repair and maintenance business include:
-
Client
-
Service advisor
-
Parts counter person
-
Technician
We consider the following use case subjects for this business:
-
Front desk - subject of the repair and maintenance IT system
-
Stock - subject of the stock management system
-
Workshop - subject of no IT system
-
Identify use cases and draw the corresponding use case diagram. Don’t try to be exhaustive, instead, try to use appropriately the different elements of the UML use case diagrams.
-
Give a textual description for each use case, stating the nominal scenario and the main use cases of anomalies and errors and their treatments. Several templates exist for expressing a use case. Each use case must have at least the following parts covered:
-
-
Title
-
Precondition
-
Primary Actor
-
Main Success Scenario
-
Extensions - possible alternatives of the main success scenario
|
Note
|
we are asking for textual use case descriptions. All use cases must have the same type of template. |
|
Note
|
Not only humans can be actors. |
Draw the activity diagram for the normal story where the car owner discusses with the service advisor what needs to be done on his car, then the repair plan is validated in the repair and maintenance IT system, the car enters the workshop, the stock management system gets informed of the needed parts, the parts counter person brings the needed parts to the technician and updates the system, the technician works on the car, then the clients pays the service to the service advisor and gets his car back.
A sleep apnea treatment device: UML Activity diagram
Draw an activity diagram to model the normal usage of the sleep apnea treatment device, including: levels monitoring and visualization; operating with different pressure level; decisions that the doctor and the patient may make; update to the program, etc. Draw swimlanes for the activities of the different actors.
What happens if the air stops flowing suddently? Add an interrupting edge if appropriate.
|
Note
|
Don’t try to be exhaustive, instead, try to use appropriately the different elements of the UML activity diagrams. |
Java Persistence API (JPA) entities: UML State machine diagram
Below is an slightly modified description of the JPA entities lifecycle. Identify the states and state transitions, and complete the UML state machine diagram to summarize the following specification:
After being initially created (with the keyword new), an entity object is not yet associated with an EntityManager and has no representation in the database. So their state is lost and garbage-collected as soon as they are no longer referenced.
Invoking a persist operation over an entity object creates a view for that object in the database. This operation can be cancelled using a rollback operation. Else, any change made to such an entity is going to be detected and propagated to the database. The refresh operation updates the entity object according the the latest state in the database.
After a commit operation, or when the current running Persistence Context is closed, successive changes will no longer be tracked and no automatic database synchronization is going to happen. Synchronization can start again after a merge operation.
An entity object in sync can be scheduled for deletion with the remove operation. The actual database DELETE statement will be executed after a commit, then the entity object becomes transient again. This can be cancelled with the persist operation.
Student enrolement and validation of a course: UML state machine diagrams
Students enrolled in the Machine Learning course need to learn, then prepare their case study (CS) and prepare for the written exam (WE) in parallel. The course is validate if the mark (CS+2WE)/3 is above 10/20. If the student is within the best 10% of his class, the grade is A. If the student is within the next 20% of his class, the grade is B. If the grade is above 10/20 but the previous conditions are not met, the grade is C. If the grade is between 7/20 and 10/20, the student has the choice to pass a retake and get a D if validated, or to get a F (fail), and potentially enrol for the course the next year.
Identify the states and state transitions, and write the UML state machine diagram to specify the rules of the course.
|
Note
|
this is not how things work for this course. |
Checking consistency of a class diagram
Look at the class and object diagrams below, and correct the object diagram if necessary.
Graph — Multigraph Class Diagram
Draw different class diagrams with association and multiplicities for modeling graphs, with nodes and arcs that link nodes.
-
Draw one diagram that ensures given two nodes a and b, there cannot be more than one arc going from a to b
-
Draw one diagram that ensures the graph is a tree (with no cycle)
-
Draw one diagram that allows different arcs between two nodes
-
Draw one diagram where arcs are not oriented and have a length
Naval Battle game: UML Class diagram
Draw a class diagram for describing the following situation:
The game has a set of ships with a name, position, status (standing_by, navigating, touched, sank). Ships may be created in different ways. Ships may be requested to move at a certain speed, game default speed is 1, in direction of another position. There are moored and drifting mines. Mines may be added or removed to the map. The game, and ships, have an operation next that computes the positions and statuses of the ships and drifting mines for the next iteration of the game. The main class contains an operation shoot. This operation may fail or succeed, depending if there is a ship at the given position.
JSON files: UML class and object diagrams
Below is a cheat-sheet for the JSON file format, and an example JSON document.
-
build the class diagram to model JSON Files.
-
build an object diagram for (part of) the example JSON document.
Car repair and maintenance business: UML Package and class diagrams
We consider two IT systems for this business:
-
repair and maintenance IT system
-
stock management system
We want to design the IT systems that model the following settings.
Vehicles have a type and a plate number. Cars have a schedule of preventative tasks, including control operations (e.g., motor oil change, gearbox oil control, pneumatics control), repair operations (bumper, front fender), or parts replacement (e.g., oil filter, air filter, windshield). Parts are compatible with a set of vehicle, have a unitary cost, a quantity in stock. Operation, controls, and parts replacement, have a unitary cost (cost of one person hour), a quantity (number of person-hours), and potentially a discount. Customers request repair or maintenance for their vehicle, at a certain date and a certain number of km. Parts used in an operation have a cost, a quantity, and potentially a discount. Operations Discounts may be applied to parts, operations, or globally to a repair. The global cost of a repair can be computed, with and without Value Added Tax (VAT).
Identify the classes and separate them in packages, such that each IT system uses the minimal number of classes.
Fixing errors in class diagram
Several classes presented in the figure below have attributes which are actually pointers to other classes. These pointers could be replaced by associations between classes. Modify the class diagram accordingly and also take into account the following information:
-
A person can work for up to three companies.
-
Each person has an identifier (ID).
-
A car also has an identifier (ID). The car is owned by a person, a bank or a company.
-
The ID of the owner of a car is the ID of the person, company or bank that owns the car.
-
Banks give loans for buying cars.
Student Life: UML Class diagram
A student undertakes examinations for different subjects.
For each test, he receives a score.
Finally, according to his results, he receives a diploma with a mention.
He is also assigned to a single room.
The class diagram in the figure below represents this description.
Class Work describes the subject of the examination; the solution provided by the student is not
stored in the information system.
-
Justify and correct the association class
Notationwith the attributerating, qualifying the association betweenStudentandWork. -
Justify and correct the class diagram (do not waste time adding attributes)
Comparing Class diagram models
Comment and compare the advantages and disadvantages of the
two approaches illustrated in the figures below (inheritance vs. delegation).
To support your point, use the specific case of creating a Dog object.
We may also consider changes in regime.
Smart Lift: Class and Communication diagram
Concerning the figures below:
-
Correct the class diagram so that the static structure of the system implements the dynamic behavior described in the communication diagram. For each change, justify and argue.
-
Draw the sequence diagram corresponding to the communication diagram.
-
How would it change the communication diagram to indicate that the flow of execution of method calls between classes takes place through the execution of the operation lift up.
Class diagram for Gardening Domain
A gardener does two types of jobs: watering and hoeing. The former consists in watering the plants (tulips, geraniums or eucalyptus) with a tool (watering can or hose) containing water and the latter consists in turning the soil with a tool (spade or shovel) to put in the fertilizer. In other words, the gardener uses a tool (watering can, hose, shovel or spade) to bring a resource (water or fertilizer) on a natural object (land or plants); it is produced by a work activity (spraying or hoeing).
-
Draw a class diagram in which you will show the generalization relationships
-
Draw an object diagram corresponding to the following setting:
-
Jacques is a gardener who waters 3 geraniums with a watering can which is full of water.
-
Jules is a gardener who picks up the earth with a shovel to put the fertilizer.
-
Draw an initial class diagram with
Gardener,Watering,WateringCan,WaterandGeraniumclasses. -
Then draw another class diagram similar to the first but with more general classes:
Gardener,Labor,Tools,Resources,NaturalObject. -
What difficulties arise with classes
Water,Land,Fertilizer? -
Place the multiplicity notations on the 2 previous diagrams.
Class diagram for Booking flight domain
To model booking flights for a travel agency, interviews with business experts produced the following sentences:
-
Airline companies offer various flights.
-
A flight is opened and closed by order of the company.
-
A customer can book a flight or more, for different passengers.
-
A reservation concerns one flight and one passenger.
-
A booking may be canceled or confirmed.
-
A flight has a departure airport and an arrival airport.
-
A flight has a day and time of departure, and a day and time of arrival.
-
A flight may include stopovers at airports.
-
A stopover has arrival and departure times.
-
Each airport serves one or more cities.
Build the class diagram from the knowledge expressed above.
Class and Object diagram for Expression Evaluation
Write a class diagram to represent the expressions with binary operators, and the object diagram for the following expression: (X + Y / 2) / (X / 3 + Y).
Parentheses are shown here for associativity reasons, but should not appear in the diagram. Update the class diagram in order to take into account unary operators.
Class diagram for Products Management in a company
In a company, two types of parts are considered: the basic parts that are purchased from outside, and composite parts, which are obtained by the assembly of other parts (composite or basic).
We want to build an information system to manage all these pieces unitarily. We store information like the names of the parts, cost of assembling a composite part, and the list of parts used in its building. For each basic part, we store its name and its unit price.
-
We want to calculate the cost of a composite part with a known name.
-
We want to control the exact number of basic parts used in the production of a part.
Draw the class model satisfying all these requirements.
Class diagram for Dining Philosophers
Prepare a class diagram for the problem of dining philosophers. Five philosophers are around a circular table on which are placed 5 forks. Each philosopher has access to two forks on each side of his plate. Each fork is shared by two philosophers. Each fork can either be on the table or used by one of the philosophers. A philosopher must have two forks to eat.
Class diagram for the Human Society
In human society, the laws regulating relations between individuals (men, women, children …) are the following:
-
No one can be both a man and a woman.
-
Each person is necessarily a man or a woman.
-
Women have no more than one husband.
-
Only men may have a wife who must be a woman.
-
Men have no more than one wife.
-
A mother is necessarily a married woman.
-
Only women may have a husband who must be a man.
-
Only adult women may be married.
Behavioral diagrams
Sequence diagram
Express in a sequence diagram how a map-less automated vacuum cleaner operates in a room with obstacles and rugs. The vacuum cleaner needs to rise the suction power when on a rug.
State diagram
Describe the state diagram of the class whose behavior is described below.
enum State {Locked, Unlocked};
enum Event {Pass, Coin};
void Unlock();
void Lock();
void Thankyou();
void Alarm();
void Transition(Event e) {
static State s = Locked;
switch(s) {
case Locked:
switch(e) {
case Coin:
s = Unlocked;
Unlock();
break;
case Pass:
Alarm();
break;
}
break;
case Unlocked:
switch(e) {
case Coin:
Thankyou();
break;
case Pass:
s = Locked;
Lock();
break;
}
break;
}
}
Checking Consistency of Sequence diagram and State Diagram
Correct the sequence diagram below to conform to the state
diagrams of classes Sender and Receiver.
State diagram for a Cash Register
A cash register operates as follows:
-
When the cash register receives the entry new sale (NS), it waits and prepares for a new sale: set to 0 the totalizer, print shop logo and date of sale.
-
The cash register then receives a series of articles. An item is either weight (WA) or Unit (UA) article, and the cash register recognizes that these are two different entries and provides a table of prices of different articles (WA, UA).
-
For each item it calculates the total price taking into account the unit price and the quantity.
-
At the end of the sale (ES), the cash register will print the contents of the totalizer and stops.
Build some sequence diagrams representing the operating scenarios of the cash register (at least one case weight article sale and another for the case unit article sale). Make your assumptions clear. Construct the state diagram for class CashRegister.
Class, Sequence and State diagrams for Fuel Management
A computer system is required to control fuel flow, manage the payment from customers and control the level of fuel tanks of a petrol station. This service station has 3 pumps, one for each grade of gasoline available (regular, medium and super).
A customer who wishes to obtain supplies of gasoline goes at the pump of the appropriate category, presses a button to have permission to use the pump. Alerted by a beep on his terminal, the employee provides service authorization from its terminal and the pump motor turns on. The customer enters the amount he wants to be equivalent in essence, leaves the nozzle from his holster, and pulls its trigger; gas begins to flow.
A meter in the pump sends a signal to the system for each 1/100 of a liter of gasoline passed, thus permanently display on the screen of the pump volume and the amount of gasoline received. Once the requested amount is reached, the pump stops pumping, by automatically relax the trigger. The client can also make up the relaxation of the pump manually before reaching the amount originally sought.
In both cases, the engine stops, the customer puts the nozzle in his holster and goes to the employee's service to pay the amount due. The transactions are stored until the customer's payment. Payment can be made in cash, by credit card or account. A receipt may be required by the client.
It should be noted that the station currently has three tanks, each with a grade of gasoline (regular, medium or super). The level of each tank must not fall below 4\% of its capacity. If this happens to a tank, pump served by him can not deliver gasoline.
-
Give the object model of the gas station.
-
Give the sequence diagram describing the scenario of gasoline supply.
-
Give the state diagram of class
Pump.
Sequence and State diagrams for Conveying System
A conveying system for coal includes a trolley moving on a
rail, and transporting coal from a loading area to an unloading
area. The loading of coal at the loading area is carried by a
crane. A set of sensors are positioned on such equipment and emit a
set of events (in the rest of the problem we will consider that
these events other than those issued by the crane and trolley are
issued by an entity called Controller). Two classes can represent
this problem: Trolley and Crane.
-
The trolley is composed of a bucket that is able to switch and restore, allowing it to unload coal. The truck receives events
start,stop,trolleyFull,loadingPosition,unloadingPosition, and delivers eventstrolleyArrival,trolleyDeparture. -
The crane has a shovel, allowing it to load or unload coal. It also has an arm that rotates from right to left to access the coal pile, then empty the cart. It receives events
stop,trolleyFull,trolleyArrival,trolleyDeparture, andstopSwiveling. -
Build few sequence diagrams representing the operating scenarios between the crane and trolley for the system use case,
-
Build state diagrams for classes
CraneandTrolley.
Class diagram for Graphic Editor
Prepare a UML class diagram for a graphic editor. The attributes of classes are not required.
The documents handled by the editor are composed of layers. Each layer contains graphic objects, including text, geometric objects and groups. A group is simply a set of graphical objects, including possibly other groups. A group must contain at least two graphic objects. A graphic object may be a direct member of only one group. Geometric objects include circles, ellipses, rectangles. lines and squares.
Then add the following operations: select, copy, cut, paste, rotate, print, change font, change style, change size, enlarge, reduce, save.
\emph{Reminder: You can use the same operation in more than one class.}
Class and Communication diagrams for a Phone
Consider the software that controls a very
simple cellular telephone. Such a phone has buttons for dialing
digits, and a send'' button for initiating a call. It has
dialer'' hardware and software that gathers the digits to be
dialed and emits the appropriate tones. It has a cellular radio
that deals with the connection to the cellular network. It has a
microphone, a speaker, and a display.
Draw the class diagram corresponding to this description.
Let us look at the way the phone works. To keep things simple, we just consider how a customer might make a phone call.
The use case for this interaction looks like this:
-
User presses the digit buttons to enter the phone number.
-
For each digit, the display is updated to add the digit to the phone number.
-
For each digit, the dialer generates the corresponding tone and emits it from the speaker.
-
User presses ``Send''
-
The ``in use'' indicator is illuminated on the display
-
The cellular radio establishes a connection to the network.
-
The accumulated digits are sent to the network.
-
The connection is made to the called party.
Draw the communication diagram corresponding to this use case.
Class, Sequence and State diagrams for a Watch
A watch with digital display has two buttons A and B and two modes of operation: {"}Display Time{"} and {"}Update Time{"}. In {"}Display Time{"} mode, hours and minutes are displayed. Mode {"}Update Time{"} has two sub{}-modes: {"}Update hours{"} and {"}Update minutes{"}.
The A button lets you select a mode: {"}Display
Time{"}, {"}Update hours{"} and
{"}Update minutes{"}.
The B button allows you to increment the hours or minutes. A button should be released so that it generates another event.
Create the state diagram of class `Watch`.
State diagram for Electric Trains
The direction control for the first electric trains toys are made by interrupting the supply of the train. Prepare a state diagram for the front lights and the wheels corresponding to the following scenario:
-
the power is cut, the train does not move.
-
power is restored, the train moves forward and the front lamps are lit,
-
the power is cut, the train stops and the front lights go out,
-
power is restored, the front lights are on and the train doesnot move,
-
the power is cut, the lights go out,
-
power is restored, the train moves back and front lights are lit,
-
the power is cut, the train stops and the lights go out,
-
power is restored, the front lights are on and the train does not move,
-
the power is cut, the lights go out,
-
power is restored, the train moves forward and the front lamps are lit.
State diagram of a telephone line
The state diagram shown in figure below is the state diagram of a telephone line which we have seen usage scenarios in the course.
-
reveal the activities and actions
-
structure the model with super-states to simplify
Class, Sequence and State diagrams for a Company
Company C manufactures metal parts made in his workshop. Company C has only business relationship with regular customers. Invoices are paid monthly: all orders from a customer in the month are billed at the end of the month. Upon receipt of an order, the secretariat of Company C produces a \ manufacturing coupon and transmits it to the workshop (a duplicate of the manufacturing coupon is sent to the client). Once the part is manufactured, the workshop complements the manufacturing coupon and transmits to the Secretariat who records the end date of manufacture and inform the customer that his order is available at the workshop.
At the end of the month, invoices are produced. An invoice is published for each customer who placed an order this month. If an invoice is not paid within 10 days then a reminder letter is sent to the client: until he paid his bill any of his orders will be accepted every time that he will place an order; a denial letter will be sent to the customer.
A paid invoice is archived 10 years and then destroyed.
Hypothesis: We believe that all payments are correct: a client pays the total invoice or it does pay.
Out of scope: registration of new client is out of the scope.
