0% found this document useful (0 votes)
324 views14 pages

SDA Documents

The document discusses exercises from a software design and architecture class, including preparing class diagrams from object diagrams about countries and borders, polygons and points, families, and an air transportation system. The exercises involve adding information like multiplicity, association names, and operations to class diagrams and preparing object diagrams based on scenarios.

Uploaded by

Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views14 pages

SDA Documents

The document discusses exercises from a software design and architecture class, including preparing class diagrams from object diagrams about countries and borders, polygons and points, families, and an air transportation system. The exercises involve adding information like multiplicity, association names, and operations to class diagrams and preparing object diagrams based on scenarios.

Uploaded by

Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

University Of Kotli AK

Assignment # 03
Roll No: 24

Topic: Chp 3 Exercises

Department: BS (SE) 4th

Session: 2018-22

Subject: Software Design & Architecture

Submitted to: Umm-e-Habiba

Submitted by: Dawood Bin Azad

Date: 24-11-2020
Class Modeling
Exercises
Q.3.1 (3) Prepare a class diagram from the object diagram in Figure E3.1.

Spain:Country France:Country Belgium:Country


Borders Borders
name=“Spain” name=“France” name=“Belgium”

Figure E3.1 Object diagram for a portion of Europe

Answer: Figure A3.1 shows a class diagram for international border.

*
Country
 Borders
name
*

Figure E3.1 Class diagram for international border.

Q3.2 (5) Prepare a class diagram from the object diagram in Figure E3.2. Explain your
multiplicity decisions. Each point has an x coordinate and a y coordinate. What is the smallest
number of points required to construct a polygon? Does it make a difference whether or not a
point may be shared between polygons? Your answer should address the fact that points are
ordered.

:Point :Point
xCoord=-10 xCoord=-10
Has Has
Ycoord=10 Ycoord=10

:Polygon

:Point :Point
xCoord=-10 Has Has xCoord=-10
Ycoord=10 Ycoord=10

Figure E3.2 Object diagram for a polygon that happens to be a square


Answer:
Figure A 3.2 shows a class diagram for polygons and points.The smallest number of points
required to construct a ploygon is tree. The multiplicity of the association depends on how points
are identified. If a point is identified by its location ,then points are shared and the association is
many-to-many.On the other hand, if each point belongs to exactly one polygon, then several
points may have the same coordinates.The next answer clarifies the distribution.

Point
1 3..*
Polygon xCoord
{ordered} Ycoord

Figure A3.2 Class diagram for polygon and points

Q3.3 (5) Using your class diagram for Exercise 3.2, prepare an object diagram for two triangles
with a common side under the following conditions.

a. A point belongs to exactly one polygon.

b. A point belongs to one or more polygons.

Answer:a. Figure A 3.3 show s objects and links for two triangles with a common side in
which a point belongs to exactly one polygon.

b. Figure A 3.4 shows objects and links for two triangles with a common side in which points
may be shared.
:Point
xCoord=0
YCoord=1
:Point :Point
xCoord=-1 xCoord=-1
YCoord=0 :Polygon YCoord=0

:Point :Polygon :Point


xCoord=-1 xCoord=1
YCoord=0 YCoord=0
:Point
xCoord=0
Figure E3.3 Object diagram where each point belongs to exactly one polygon
YCoord=-1

:Point
xCoord=0
YCoord=1
:Polygon
:Point :Point
xCoord=-1 xCoord=1
YCoord=0 YCoord=0
:Polygon

:Point
xCoord=0
YCoord=1

Figure A3.4 Object diagram where each point can belong to multiple polygons

Q3.4 (5) Prepare a class diagram from the object diagram in Figure E3.3. How does your
diagram express the fact that points are ordered? Assume that a point belongs to at most one
polygon.

Answer: Figure A3.5 shows the class diagram—this is a poor model. Figure A3.5 has some
flawsthat Figure A3.2 does not have. Figure A3.5 permits a degenerate polygon which con-sists
of exactly one point. (The same point is first and last. The point is next to itself.)The class
diagram also permits a line to be stored as a polygon. Figure A3.5 does notenforce the constraint
that the first and last points must be adjacent.Figure A3.2 and Figure A3.5 share other problems.
The sense of ordering is problem-atic. A polygon that is traversed in left-to-right order is stored
differently than one thatis traversed in right-to-left order even though both visually appear the
same. There is noconstraint that a polygon be closed and that a polygon not cross itself. In
general it is difficult to fully capture constraints with class models and you must choose
betweenmodel complexity and model completeness.

Q3.5 (2) Prepare a written description for the class diagrams from Exercise 3.2 and Exercise
3.4.
Answer: Description for Figure A3.2.A polygon consists of at least three points; each point
hasan x coordinate and a y coordinate. Each point belongs to exactly one polygon butwhether or
not this constraint is required was not made clear by the exercise statement.The points in a
polygon are stored in an unspecified order.

Description for Figure A3.4.A polygon has a first and a last point. Each point hasan x coordinate
and a y coordinate. A point may be first, last, or in the middle of a se-quence for a polygon. Each
point belongs to at most one polygon. Each point is linkedto its next point.

Q3.6 (6) Prepare a class diagram from the object diagram in Figure E3.4.

Answer:

Class Diagram: Person


Name
Birthday

Child

Mate Cousin

Sibling

Figure E3.4.Class Diagram for a family

Q3.7 (5) Prepare a class diagram from the object diagram in Figure E3.5. This particular
document has 4 pages. The first page has a red point and a yellow square displayed on it.
The second page contains a line and an ellipse. An arc, a circle, and a rectangle appear on
the last two pages. In preparing your diagram, use one or more generalizations.

Answer:
-page -shapes
Page Shape
1..* 0..*

0-Dimensional 1- Dimensional 2- Dimensional

Point Line Arc

Ellipse circle

Rectangle

Q3.8 (4) Figure E3.6 is a partially completed class diagram of an air transportation
system. Multiplicity has been omitted. Add multiplicity to the diagram. Demonstrate how
multiplicity decisions depend on your perception of the world.

Answer:

3.9: Add association names to the unlabeled associations in Figure E3.6.

Answer:
Q3.10 (3) Add association end names to Figure E3.6. Add only meaningful names that are different from
the class names. You should add at least six association end names to the diagram.

Q3.11 (2) Add the following operations to the class diagram in Figure E3.6: heat, hire, fire, refuel,
reserve, clean, de-ice, take off, land, repair, cancel, delay. It is permissible to add an operation to more
than one class.
Q3.12 (6) Prepare an object diagram for an imaginary round trip you took last weekend to London.
Include at least one instance of each class. Fortunately, direct flights on a hypersonic plane were
available. A friend went with you but decided to stay a while and is still there. Captain Johnson was your
pilot on both flights. You had a different seat each way, but you noticed it was on the same plane
because of a distinctive dent in the tail section. Students should indicate unknown values with a “?”.

3.13 Prepare a class diagram for each group of classes. Add at least 10 relationships (associations and
generalizations) to each diagram. Use association names and association end names where

Figure E3.6 Partially completed class model of an air transportation system

needed. Also use qualified associations and show multiplicity. You do not need to show attributes or
operations. As you prepare the diagrams, you may add classes. Be sure to explain your diagrams. a. (6)
school, playground, principal, school board, classroom, book, student, teacher, cafeteria, restroom,
computer, desk, chair, ruler, door, swing b. (4) automobile, engine, wheel, brake, brake light, door,
battery, muffler, tail pipe c. (4) castle, moat, drawbridge, tower, ghost, stairs, dungeon, floor, corridor,
room, window, stone, lord, lady, cook

d. (8) expression, constant, variable, function, argument list, relational operator, term, factor, arithmetic
operator, statement, computer program e. (6) file system, file, ASCII file, binary file, directory file, disc,
drive, track, sector f. (4) gas furnace, blower, blower motor, room thermostat, furnace thermostat,
humidifier, humidity sensor, gas control, blower control, hot air vent g. (7) chess piece, rank, file, square,
board, move, tree of moves h. (4) sink, freezer, refrigerator, table, light, switch, window, smoke alarm,
burglar alarm, cabinet, bread, cheese, ice, door, kitchen

Q 3.14 (4) Add at least 10 attributes and at least 5 methods to each of the class diagrams you prepared
in the previous exercise.

Q 3.15 (6) Figure E3.7 is a portion of a class diagram for a computer program for playing several types of
card games. Deck, hand, discard pile, and draw pile are collections of cards. The initial size of a hand
depends on the type of game. Each card has a suit and rank. Add the following operations to the
diagram: display, shuffle, deal, initialize, sort, topOfPile, bottomOfPile, insert, draw, and discard. Some
operations may appear in more than one class. For each class in which an operation appears, describe
the arguments to the operation and what the operation should do to an instance of that class.

Figure E3.7 Portion of a class diagram for a card-playing system

Q3.16 (5) Figure E3.8 is a portion of a class diagram for a computer system for laying out a newspaper.
The system handles newspaper pages which may contain, among other things, columns of text. The user
may edit the width and length of a column of text, move it around on a page, or move it from one page
to another. As shown, a column is displayed on exactly one page.

Figure E3.8 Portion of a class diagram for a newspaper publishing system


Modify the class diagram so that portions of the same column may appear on more than one page. If the
user edits the text on one page, the changes should appear automatically on other pages. You should
change x location and y location into attributes of an association.

Q 3.17 (6) Figure E3.9 is a class diagram that might be used in developing a system to simplify the
scheduling and scoring of judged athletic competitions such as gymnastics, diving, and figure skating.
There are multiple events and competitors. Each competitor may enter several events and each event
has many competitors. Each event has several judges who subjectively rate the performance of
competitors in that event. A judge rates every competitor for an event. In some cases, a judge may score
more than one event. Trials are the focus of the competition. Each trial is an attempt by one competitor
to perform his or her best in one event. A trial is scored by the panel of judges for that event and a net
score determined. Add multiplicity to the diagram.

Competitor Trial Event

Score Judge
Figure E3.9 Portion of a class diagram for an athletic-event scoring system.

Q3.20 (6) Prepare a class model to describe undirected graphs. An undirected graph consists of a set of
vertices and a set of edges. Edges connect pairs of vertices. Your model should capture only the
structure of graphs (i.e., connectivity) and need not be concerned with layout such as location of
vertices or lengths of edges. Figure E3.10 shows a typical undirected graph.

Figure E3.10 Sample undirected graph

Answer: Graphs occur in many applications. Several variation of the model are possible,
depending on your viewpoint. Figure A3.23 accurately represents undirected graph as described
in the exercise. Although not quite as accurate , your answer could omit the class Undirected
Graph. We have found it useful for some graph related queries to elevate the association between
vertices and edges to the status of a class as Figure A3.24 shows.

Q3.21 (4) Prepare an object diagram for Figure E3.10. [Instructor’s note: You may want to give the
students our answer to Exercise 3.20.] Figure E3.9 Portion of a class diagram for an athletic-event
scoring system Judge Event Score Competitor Trial e1 e2 e3 e4 e5 e6 v1 v2 v3 v5 v4 Figure E3.10 Sample
undirected graph Exercises 57

Q3.22 (5) Extend the class diagram you prepared in Exercise 3.20 with layout details, including
locations of vertices and thickness and color of edges. Also add names of vertices and edges.
[Instructor’s note: You may want to give the students our answer to Exercise 3.20.]
Q 3.23 (7) Prepare a class model to describe directed graphs. A directed graph is similar to an
undirected graph, except the edges are oriented. Figure E3.11 shows a typical directed graph.

Answer: Figure A3.27 shows a class diagram describing directed graph s. The distribution
between the two ends of an edge is accomplished with a qualified association. Value of the
qualifier end are from and to. Figure A 3.28 shows another represent ation of directed graphs.
The distinction between the two ends of an edge is accomplished with separate association.

:Point
xCoord=0
YCoord=1

:Point :Point
xCoord=-1 xCoord=-1
:Polygon YCoord=0
YCoord=0

:Point :Polygon :Point


xCoord=-1 xCoord=1
YCoord=0 YCoord=0

:Point
xCoord=0
YCoord=-1

Figure E3.2 Object diagram where each point belongs to exactly one polygon
:Point
xCoord=0
YCoord=1
:Polygon
:Point :Point
xCoord=-1 xCoord=-1
YCoord=0 YCoord=0
:Polygon

:Point
xCoord=0
YCoord=1

Q3.24 (4) Prepare an object diagram for Figure E3.11. [Instructor’s note: You may want to give the
students our answer to Exercise 3.23.]

Q3.25 (7) Several classes shown in Figure E3.12 have attributes that are really references to other
classes and could be replaced with associations. A person may have up to three companies as
employers. Each person has an ID. A car is assigned an ID. Cars may be owned by persons, companies, or
banks. Owner ID refers to the ID of the person, company, or bank who owns the car. A car loan may be
involved in the purchase of a car. Burying object references as references is the incorrect way to
construct a model. Prepare a class diagram without IDs and using association and generalization. Try to
assign multiplicities. You may need to add one or more classes of your own.

Person Car CarLoan Company Bank


name owner ID vehicle ID name name
birthdate vehicle ID customer Type company I
employer1ID owner Type customer ID bank ID
employer2ID model year account Number
employer3ID bank ID
person ID
address interest Rate

current Balance

Figure E3.12 Classes with some attributes that are references.

Answer:
Figure 3.12 shows a class diagram of car loans in which pointers are replaced with associations.
In this form the arguably artificial restriction that a person have no more than threw employees
has been eliminated. Note that in this model an owner can own several cars. A car can have
several loans against it. Banks loan money to persons companies and other banks. 

Owner 1 Owns

name 1 Borrow *

Car

model
1
year
lends *
Person Bank Loan
1 Company *
birthdate account Number
*
address interest Rate
* employment *
current Balance

Proper Class diagram for a car loans.

Q3.26 (4) A problem arises when several independent systems need to identify the same object. For
example, the department of motor vehicles, an insurance company, a bank, and the police may wish to
identify a given motor vehicle. Discuss the relative merits of using the following identification methods:
a. Identify by its owner b. Identify by attributes such as manufacturer, model, and year e1 e2 e3 e4 e5 e6
v1 v2 v3 v5 v4 Figure E3.11 Sample directed graph Bank name bankID Company name companyID Figure
E3.12 Classes with some attributes that are references. Car ownerID vehicleID ownerType model year
CarLoan vehicleID customerType customerID accountNumber bankID interestRate currentBalance
Person name birthdate employer1ID employer2ID employer3ID personID address 58 Chapter 3 / Class
Modeling c. Use the vehicle identification number (VIN) assigned to the car by its manufacturer d. Use
IDs generated internally by each interested agency

3.27 (7) Prepare a class model that might be used to troubleshoot a 4-cycle lawn mower engine. Use
three separate diagrams for the model, with one diagram for each of the following paragraphs. Power is
developed in such an engine by the combustion of a mixture of air and gasoline against a piston. The
piston is attached to a crankshaft via a connecting rod, and it moves up and down inside a cylinder as
the shaft rotates. As the piston moves down, an intake valve opens, allowing the piston to draw a
mixture of fuel and air into the cylinder. At the bottom of the stroke, the intake valve closes. The piston
compresses and heats the mixture as it moves upward. Rings in grooves around the piston rub against
the cylinder wall, providing a seal necessary for compression and spreading lubricating oil. At the top of
the stroke, an electrical spark from a spark plug detonates the mixture. The expanding gases develop
power during the downward stroke. At the bottom, an exhaust valve is opened. On the next upward
stroke, the exhaust gases are driven out. Fuel is mixed with air in a carburetor. Dust and dirt in the air,
which could cause excessive mechanical wear, are removed by an air filter. The optimum ratio of fuel to
air is set by adjusting a tapered mixture screw. A throttle plate controls the amount of mixture pulled
into the cylinder. The throttle plate, in turn, is controlled through springs by the operator throttle
control and a governor, a mechanical device which stabilizes the engine speed under varying mechanical
loads. Intake and exhaust valves are normally held closed by springs and are opened at the right time by
a cam shaft, which is gear driven by the crankshaft. The electrical energy for the spark is provided and
timed by a magnet, coil, condenser, and a normally closed switch called the points. The coil has a low-
voltage primary circuit connected to the points and a high-voltage secondary connected to the spark
plug. The magnet is mounted on a flywheel and as it rotates past the coil, it induces a current in the
shorted primary circuit. The points are driven open at the right instant by a cam on the crankshaft. With
the aid of the condenser, they interrupt the current in the primary circuit, inducing a high-voltage pulse
in the secondary.

Q3.28 (6) Prepare a class diagram for the dining philosopher problem. There are 5 philosophers
and 5 forks around a circular table. Each philosopher has access to 2 forks, one on either side.
Each fork is shared by 2 philosophers. Each fork may be either on the table or in use by one
philosopher. A philosopher must have 2 forks to eat.

Answer: Figure A 3.30 shows a class diagram for the dining philosopher problem. The one-to-
one sociations describe the relative locations of philosopher and forks. The in use association
describes who is using forks. Other representation are possible, depending on your viewpoint. An
object diagram may help you better understand this problem.

right Diner 1 1 right Fork

0..1 in Use 0..2


Philosopher Fork
fork User
left Diner 1 1 left Fork

Class diagram for the doing philosopher problem.

Q 3.29 (7) The tower of Hanoi is a problem frequently used to teach recursive programming
techniques. The goal is to move a stack of disks from one of three long pegs to another, using the third
peg for maneuvering. Each disk is a different size. Disks may be moved from the top of a stack on a peg
to the top of the stack on any other peg, one at a time, provided a disk is never placed on another disk
that is smaller than itself. The details of the algorithm for listing the series of required moves depend on
the structure of the class diagram used. Prepare class diagrams for each of the following descriptions.
Show classes and associations. Do not show attributes or operations: a. A tower consists of 3 pegs. Each
peg has several disks on it, in a certain order. b. A tower consists of 3 pegs. Disks on the pegs are
organized into subsets called stacks. A stack is an ordered set of disks. Every disk is in exactly one stack.
A peg may have several stacks on it, in order. c. A tower consists of 3 pegs. Disks on the pegs are
organized into subsets called stacks, as in (b), with several stacks on a peg. However, the structure of a
stack is recursive. A stack con- Exercises 59 sists of one disk (the disk that is physically on the bottom of
the stack) and zero or one stack, depending on the height of the stack. d. Similar to (c), except only one
stack is associated with a peg. Other stacks on the peg are associated in a linked list.

Q 3.30 (8) The recursive algorithm for producing the series of moves described in the previous
exercise focuses on a stack of disks. To move a stack of height N, where N > 1, first move the stack of
height N − 1 to the free peg using a recursive call. Then move the bottom disk to the desired peg. Finally,
move the stack on the free peg to the desired peg. The recursion terminates, because moving a stack of
height 1 is trivial. Which one of the several class diagrams that you prepared in the previous exercise is
best suited for this algorithm? Discuss why. Also, add attributes and operations to the diagram. What
are the arguments for each operation? Describe what each operation is supposed to do to each class for
which it is defined. Q3.31 (6) Consider Figure E3.6. Write an OCL expression to compute the set of
names of airlines that a person flew in a given year. Assume you have a function getYear(date) that
extracts the year given a date. (Instructor’s note: You should give the students our answer to Exercise
3.10 as the basis for this exercise.)

Q3.32 (6) Consider Figure E3.6. Write an OCL expression to find the nonstop flights from aCity1 to
aCity2. (Instructor’s note: You should give the students our answer to Exercise 3.10 as the basis for this
exercise.)

Q3.33 (6) Consider Figure E3.9. Write an OCL expression to find the total score a competitor received
from a judge. (Instructor’s note: You should give the students our answer to Exercise 3.18 as the basis
for this exercise.)
Q3.34 (6) Compare the class models in Figure E3.13. The left model represents Subscription as an
association class; the right model treats Subscription as an ordinary class. A person may have multiple
magazine subscriptions. A magazine has multiple subscribers. For each subscription, it is important to
track the date and amount of each payment as well as the current expiration date.

Figure E3.13 Class diagram for magazine subscriptions

Answer: 3.34 Figure E 3.13 (a) state that a subscription has derived identity . Figure E 3.13(b)
gives subscription more prominence and promote s subscription to a class. The (b) model is a
better model . Most copies of magazines have subscription code on their mailing labels; this
could be stored as an attribute. The subscription code is intended to identify subscription;
subscription are not identify by the combination of a person and a magazine, so we should
promote Subscription to a class. Furthermore, a person might have multiple subscription to a
magazine ; only the (b) model can b readily accommodate this.

You might also like