Modelling Exercises

Modelling Exercises - Page 1

Object Modelling Exercises

1. The following sentences suggest parts of object models. Draw simple diagrams using whichever of the following relations you feel is most appropriate.

  • generalisation-specialisation (inheritance)
  • whole-part (aggregation)
  • association
  • object is instance of class

a)A country has a capital city.

b)A file is a text file or an executable file.

c)Files contain records.

d)A person eats with a fork.

e)Alan Shearer is a soccer player.

f)A polygon is built from a number of points.

g)A screen-object may be either text or a figure.

h)Mouse and keyboard are different input devices.

i)A Volvo is a car.

j)A class can have multiple attributes.

k)A player may play for only one team in each season’s cup competition.

l)My car is a Honda.

m)A motorway links cities.

n)A programmer is using a specific programming language on a project.

Consider alternatives to the models you have drawn and discuss why one model might be preferred to another.

2.Prepare an object model to describe unidirected graphs. An unidirected 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 geometrical details such as location of vertices or lengths of edges. A typical graph is shown below.

3. Prepare an object (instance) diagram for the above graph.

4. Prepare a class diagram for a graphical document editor that supports grouping, which is a concept used in a variety of graphical editors. Assume that a document is composed of several sheets. Each sheet contains drawing objects, including text, geometrical objects and groups. A group is simply a set of drawing objects, possibly including other groups. A group must contain at least two drawing objects. A drawing object can be a direct member of at most one group. Geometrical objects include circles, ellipses, rectangles, lines and squares.

5. The following is a partial taxonomy of rotating electrical machines. Electrical machines may be categorised for analysis purposes into alternating current (AC) or direct current (DC). Some machines run on AC, some on DC, and some will run on either. An AC machine may be synchronous or induction. A few examples of electrical machines include large synchronous motors, small induction motors, universal motors and permanent magnet motors. Most motors found in the home are usually induction machines or universal motors. Universal motors are typically used when high speed is needed such as in blenders or vacuum cleaners. They will run on either AC or DC. Permanent magnet motors are frequently used in toys and will work only on DC. Prepare an object diagram showing how the categories and machines just described relate to one another. Use multiple inheritance where it is appropriate to do so.

Modelling Exercises - Page 1

Dynamic Modelling Exercises

6.The direction control for some of the first toy electric trains was accomplished by interrupting the power to the train. Prepare state diagrams for the headlight and wheels of the train, corresponding to the following scenario:

Power is off, train is not moving.

Power is turned on, train moves forward and train headlight shines.

Power is turned off, train stops and headlight goes out.

Power is turned on, headlight shines and train does not move.

Power is turned off, headlight goes out.

Power is turned on, train runs backward with its headlight shining.

Power is turned off, train stops and headlight goes out.

Power is turned on, headlight shines and train does not move.

Power is turned off, headlight goes out.

Power is turned on, train runs forward with its headlight shining.

  1. A simple digital watch has a display and two buttons to set it, the A button and the B button. The watch has two modes of operation, display time and set time. In the display time mode, hours and minutes are displayed separated by a flashing colon. The set time mode has two sub-modes, set hours and set minutes. The A button is used to select modes. Each time it is pressed, the mode advances in the sequence: display, set hours, set minutes, display, etc. Within the sub modes, the B button is used to advance the hours or minutes each time it is pressed. Buttons must be released before they can generate another event. Prepare a state diagram for the watch.

8.Training course events are planned by each department, but only advertised after approval by the Training Manager (TM). Bookings are accepted on a provisional basis until the threshold attendance is reached. Course events should be confirmed or cancelled at least 3 weeks beforehand, after which bookings are confirmed, and only confirmed new bookings accepted. Lecturer(s) and room bookings must be confirmed before confirming the course. If a decision to confirm or cancel has not been made 2 weeks before the course, the course is flagged as "decision pending", the relevant Managers are alerted, and no further bookings are accepted until the course is confirmed or cancelled. Events may be cancelled at any stage up to the start date, but cancellation after confirmation triggers compensation to customers with confirmed bookings. Customers can cancel without penalty up to course confirmation. Cancellations between confirmation and the course starting result in partial refunds.
Draw a state diagram for the “CourseEvent” class.

9.Whilst exploring an old castle, you and a friend discovered a bookcase that you suspected to be the entrance to a secret passageway. While you examined the bookcase, your friend removed a candle from its holder, only to discover that the candle holder was the entrance control. The bookcase rotated half a turn, pushing you along, separating you from your friend. Your friend put the candle back. This time the bookcase rotated a full turn still leaving you behind it. Your friend took the candle out. The bookcase started to rotate a full turn again, but this time you stopped it just shy of a full turn by blocking it with your body. Your friend handed you the candle and together you managed to force the bookcase back a half turn, but this left your friend behind it and you in front of it. You put the candle back. As the bookcase began to rotate, you took out the candle, and the bookcase stopped after a quarter turn. You and your friend entered to explore further.

Develop a state diagram for the control of the bookcase that is consistent with the previous scenario. What should you have done at first to gain entry with the least fuss?

Modelling Exercises - Page 1