Class Diagrams Exercises University In a university there are different classrooms, offices and departments. A department has a name and it contains many offices. A person working at the university has a unique ID and can be a professor or an employee. A professor can be a full, associate or assistant professor and he/she is enrolled in one department. Offices and classrooms have a number ID, and a classroom has a number of seats. Every employee works in an office.
University: solution Diagram made with Omondo UML tool Movie- Shop Design a system for a movie-shop, in order to handle ordering of movies and browsing of the catalogue of the store, and user subscriptions with rechargeable cards. Only subscribers are allowed hiring movies with their own card. Credit is updated on the card during rent operations. Both users and subscribers can buy a movie and their data are saved in the related order. When a movie is not available it is ordered. 2
Movie-Shop: solution.. Flights We want to model a system for management of flights and pilots. An airline operates flights. Each airline has an ID. Each flight has an ID a departure airport and an arrival airport: an airport as a unique identifier. Each flight has a pilot and a co-pilot, and it uses an aircraft of a certain type; a flight has also a departure time and an arrival time. An airline owns a set of aircrafts of different types. An aircraft can be in a working state or it can be under repair. In a particular moment an aircraft can be landed or airborne. A company has a set of pilots: each pilot has an experience level: is minimum, 3 is maximum. A type of aeroplane may need a particular number of pilots, with a different role (e.g.: captain, co-pilot, navigator): there must be at least one captain and one co-pilot, and a captain must have a level 3. 3
Flights - solution Airline ID name owns offers Aircraft - name - repair - landed uses Flight - ID -arrival_time -departure_time Driven by arrives to departs from 2..n Airport -ID -name Aircraft Type name is of Navigator of Pilot name Copilot of..n Pilot Captain of Pilot3 Pilot2 Bank system A bank system contains data on customers (identified by name and address) and their accounts. Each account has a balance and there are 2 type of accounts: one for savings which offers an interest rate, the other for investments, used to buy stocks. Stocks are bought at a certain quantity for a certain price (ticker) and the bank applies commission on stock orders. 4
Bank solution Statecharts Exercises 5
Digital Pet You re creating a digital pet program. What happens to the pet when he receives different stimuli is determined by the state he s in, so you decide to model the digital pet with a state diagram. The behavior of the digital pet program is as follows: When the pet is turned on, it starts out happy If the pet is happy and receives punishment, then he becomes sad If the pet is sad and receives praise, it becomes happy If the pet is sad and receives punishment, it is heart-broken Identify the states and transitions of the digital pet and draw a state diagram. Copyright: Russ Miles Digital pet: statechart on praise Pet Happy punishment praise Pet Sad punishment praise, punishment Heart-Broken Pet off 2 6
Calculator Draw a statechart of a simple calculator The interface of the calculator is composed of 0 buttons with digits, and 4 buttons with the basic operations (+, -,, /) The button C resets the display The button = displays the result Buttons On and OFF : try to guess. Calculator display op op2 operator - click(char key) Calculator: solution on C / display=0 NO_OP [digit] / update display C / display = 0 C / display=0 [digit] / update display [sign] / op = display = / op2 = display ONE_OP [digit] / update display TWO_OP do: update display with result [sign] / op=result [sign] / op = display [sign] means +, -,, / [digit] means 0.. 9 ALL STATES off 7
Fuel pump Model the behavior of a fuel pump controller. User can buy fuel after inserting a credit card, which is read and validated by the controller. Then the user takes the hose out of the holster, and pushes the nozzle trigger, to fuel his car. When the nozzle is off, the fuel flow is stopped and the price is charged on the credit card If invalid card or timeout the system returns to the initial waiting state. Fuel pump: solution Hose in holster 8
Activity Diagrams Exercises Model processes with activity diagram Booking a Room in a hotel When customer requests a room, the hotel employee looks for room availability, then he insert customer s data and verifies if the provided credit card number has enough credit to pay the room: in this case the booking is confirmed and we wait customer arrival. The Hotel information system allows customer to modify or cancel his/her reservation. If customer arrives he uses the room and then he pays, in case of no-show a penalty is accounted on his credit card and the booking is canceled. 8 9
Solution Use room Select Room Wait [ customer arrives ] [ cancel ] [else] [room chosen] [ modify Data] Cancel Reservation Book Room Modify Reservation y [ no show] Account Money Insert Data Verify Credit Card Confirm Reservation 9 Voting Once arrived at the polling station, elector gives the own electoral card to station president who checks if the polling station number is right. Then he checks the identity document and if ok he gives the ballot paper to the elector. Then the president waits for a cabin to get free and he gives the pencil to the elector and a secretary who signs the registry and put a print on the elector certificate. Once elector has voted, he/she inserts the ballot paper in the urn, giving back the pencil and taking back the own ID document. 20 0
Voting: solution Give certificate [ new elector] Assign free cabin Sign Registry [wrong polling station number] Give back certificate Right number Give pencil Print on card Check Document Vow [Document not valid Insert ballot paper Give Ballot paper Give back Pencil Give back Document 2 Products Management When an order is received, check client data and availbility in the inventory.if credit card data are enough to pay products, wait for payment and then send receipt. Once payment is registered in archive, client is notified of payment received If credit card data are ok, we verify if product is present in inventory, if not we have to fill order to buy it or, if the product is internally produced, we have start a production process, then the inventory is updated. Once product is ready to be sent and payment is ok, we can send product to client.
Solution [externa product] Order product [quantity not enough] [enough quantity] [internal product] Production product Receive Order Check Inventory Check client [client ok] Update Inventory Send product [client NO ok] Notify customer [NO payment [payment received] Send receipt Registration 2