An Inventory object is linked through the role products to three Product objects. Each Product has stock : Integer and maxStock : Integer. Product p has stock 37 and maxStock 120, product q has stock 95 and maxStock 100, and product r has stock 82 and maxStock 90. The operation restock has this contract:
context Inventory::restock(item : Product, qty : Integer) pre: self.products->includes(item) and qty > 0 and item.stock + qty <= item.maxStock post: item.stock = item.stock@pre + qty and self.products->excluding(item)->forAll(x | x.stock = x.stock@pre)
Find four values, each as a whole number of units: the largest qty for which the precondition of restock(p, qty) holds; then, for a valid call restock(p, 50), the value of item.stock@pre when the postcondition is evaluated, the value of p.stock after the call, and the value of self.products.stock->sum() after the call.
Unlock full course notes by signing up
Evaluating select and sum on a playlist
In a UML model, a Playlist object is linked through the role tracks to five Track objects whose duration attribute values, in seconds, are 210, 185, 342, 128 and 275. With self bound to that playlist, evaluate the OCL expression self.tracks->select(t | t.duration > 200).duration->sum(). Give your answer in seconds as a whole number.
Checking an implies invariant on accounts
A banking model has the following OCL invariant on the class Account, where type is a String and balance is a Real:
For each account in the snapshot below, type true if the invariant holds for that account and false if it is violated.
Tracking repeated parcel masses
A parcel-processing model records the mass of each parcel in kilograms. Its OCL variable masses : Bag(Integer) currently has the value Bag{12, 12, 18, 25, 25, 25}. Every value is defined.
Evaluate the following expressions. Each expression starts from the original value of masses; evaluating an expression does not change it. Enter exact integers in the result table. The results are counts, rather than masses.
E1: masses->size()
Distinguishing shared coverage from one qualified technician
A maintenance visit requires tasks P, Q, and R. In an OCL model, self.requiredTasks : Set(Task) contains exactly those three distinct task objects. Each technician has a property qualifications : Set(Task) containing exactly the task objects listed below. Every property is defined.
A candidate self.roster : Set(Technician) contains exactly two distinct technicians from this table. Consider every possible two-person roster once; selecting Ari and Bo is the same roster as selecting Bo and Ari. There are no scheduling or capacity restrictions beyond the stated OCL expressions.
Rule X is: