UML&OCL Modeling Languages
Exercises
Subject 1
Suppose you have a class Order
with the following attributes:
date
: a date representing the date the order was placed.
amount
: a decimal representing the total amount of the order.
customer
: the name of the customer who placed the order.
items
: a collection of OrderItem
objects representing the items in the order.
The OrderItem
class has the following attributes:
product
: a reference to the product being ordered.
quantity
: an integer representing the quantity of the product being ordered.
price
: a decimal representing the cost of the product.
Questions
- Represent the UML class diagram.
- Write OCL expressions that satisfy the following requirements::
a. An operation that calculates the total quantity of items in an order.
b. A constraint that ensures that the total amount of an order is greater than 0.
c. A query that returns the most expensive product in an order.
d. A constraint that ensures that the order date is not in the future.
e. A query that returns the total amount of an order including tax.
NB. Note that TaxRate is a separate class with a static operation getRate(customer: Customer) : Decimal that returns the tax rate for a given customer.
9 - 9thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL
thiry laurent ensisa uha alsace mulhouse france unified modeling modelisation language constraint object objet UML OCL