February 2006

Homework #1

 

 

A. Consider the class diagram below.

 

 

 


 

Looking at the above class diagram, we can drive that

1)      Bank customer and employee are roles played by a person

2)      A person may have relationships with other persons as wife and husband

3)      A bank customer can have any number of mortgages

4)      A mortgage belongs to exactly one bank customer

5)      A bank customer can own any number of security policies

6)      A security policy can be used to secure an arbitrary number of mortgage credits

7)      A credit card must have at least one security

8)      A security is owned exactly by one customer

9)      A company has arbitrary number of employees

10)  An employee can be employed by any number of companies

 

The classes Gender and Date are utility classes.  (Here, the meaning of Security is a tangible and valuable possession possessed by a customer in case the customer fails to pay a monthly balance)

 

The rules stated above do not describe all the constraints of this system. In the following scenario, we are asked to declare the following requirements (constraints) unambiguously.

 

1) If a person is male, he cannot have a husband and if he has a wife it must be female. If the person is female, she cannot have a wife and if she has a husband it must be male.

 

a) Person

wife -> notEmpty() implies (wife.gender=Gender::female and self.gender=Gender::male)

husband ->notEmpty implies (husband.gender=Gender::male and self.gender=Gender::female)

 

b) Person

gender=Gender::male implies self.husband ->isEmpty()

gender= Gender::male and self.wife ->notEmpty  implies wife.gender->forAll(Gender::female)

gender= Gender::female implies self.wife ->isEmpty()

gender= Gender::female and self.husband ->notEmpty  implies husband.gender->forAll(Gender::female)

 

 

2) No employee is older than 70

a) Company

self.employee ->forAll(age<=70)

b) Company

employee ->reject(age>70)->isEmpty()

 

3) If a person is employed at a company, the person is not unemployed

 

a) Company

employee.person->exists(isUmployed)=false

 

b)Employee

employer.size() >0 implies person.isUnemployed=false

 

 

4) The sum of monthly balances of all mortgage credits of a bank customer may not exceed 50% of the customer’s monthly income.

 

Customer

mortgage.monthlyBalance ->sum < self.monthlyIncome/2

 

 

5) After paying all the monthly balances, the bank customer must have at least 500 YTL available.

 

Customer

monthlyIncome-mortage.monthlyBalance->sum >=500

 

 

6) The sum of all security values of a bank customer is 20% higher than a mortgage amount.

 

Mortgage

customer.security.value ->sum > amount *1.2

 

 

7) A bank customer’s credit can only be secured by the securities owned by that customer.

 

Mortgage

security.owner ->forAll(owner | owner=self.customer)

 

 

B. Consider the following FIFO Queue class

 

 

State the preconditions and post conditions of each Queue operations in OCL.

 

 

Queue::enqueue(item:Object):void

pre:  --- 

post: object->size() = object@pre->size + 1

        and object->last()=item

        and object ->at(object ->size)=item         

        and object@pre= object ->subsequence(1, object ->size-1)

 

 

Queue::dequeue():Object

pre: object->size > 0

post: object->size = object@pre->size - 1

        and result=object@pre->first()

        and items= object@pre->subsequence(2,object->size)

 

 

Queue::isEmpty():boolean

pre: --

post: result =(object->size=0)