M225: SOFTWARE ENGINEERING Unassessed Coursework 3: Class Schema in Object Z The aim of this tutorial is to enable you to practice specifying simple problems using the basic features of Object Z notation learned in Unit 4. These questions are about specifying a WebShop system used to sell a particular type of product, over the Web. The system uses a class WareHouse, and a class Trolley. A warehouse has a maximum capacity equal to 10000, the number of current items in stock, the description of the item (of type seqchar), and the price of an item. The trolley includes the number of items identified for purchase by the user. The system Webshop includes, instead, an object of type WareHouse, an object of type Trolley, and an object of type CreditCard, as described in Unit 4. At the beginning, the warehouse in fully stocked, the trolley is empty and the balance is zero. Write down a class schema for each of the following types of objects: (Q1). “WareHouse”. The following operations can be performed on this object: - IncStock, to add a given number of units (of the item) to the current stock, - DecStock, to decrement by a given number of units (of the item) the current stock, - SellCost to give the total cost to be paid for a given number of units. - SellItems, which cojoins the operations DecStock and SellCost. - DescPrice, to provide in output the price and the description of the item, - Sale, to change the current value of price for a newprice given in input. (Q2). “Trolley”. The following operations can be performed on this object: - Add, to add a given number of units to the trolley, - Dec to decrement by a given number of units, the number of items in the trolley, - Empty, to return the number of items in the trolley and empty the trolley. (Q3). “WebShop”. The following operations can be performed on this object: - Description, to provide in output the description and price of the product, - Request, for the user to input a number of items identified for purchase. These items are moved from the warehouse to the trolley. - Cancel, to stop the transition. The trolley is empted and the items identified for purchase are moved back into the warehouse. - Buy, to complete the purchase of the items by depositing the total cost in the credit card account, and empty the trolley. M225: SOFTWARE ENGINEERING Unassessed Coursework 2: – ANSWERS Class Schema in Object Z (1). WareHouse | (Init, maxcapacity, stock, DecStock, IncStock, SellCost, DescPrice) SellItems ) Init maxcapacity: N stock = maxcapacity maxcapacity = 10000 stock: N description: seq char price: N 0 stock maxcapacity IncStock (stock) num?: N stock' = stock + num? DescPrice string! : seq char cost!: N string! = description cost! = sellprice DecStock (stock) num?: N stock maxcapacity+num? stock' = stock - num? SellCost amount!: N num?: N amount! = price * num? Sale newprice? : N (price) price' = newprice? SellItems = DecStock SellCost Note that the vertical bar for the visibility list is not exactly how it looks in the textbook, but it’s as close as my Word can get to it! (2). Trolley | (Init, NItems, Empty, Add, Init) Init NItems: N NItems = 0 Add (NItems) num?: N Dec (NItems) num?: N NItems' = NItem + num? NItems' = NItem - num? Empty (NItems) num!: N num! = NItems NItems' = 0 (3). WebShop | (Init, Description, Request, Cancel, Buy) w: WareHouse t: Trolley c: CreditCard t.NItem + w.stock = w.maxcapacity c.balance = (w.maxcapacity - w.stock) * w.price Init w.Init t.Init c.Init Description = w.DescPrice Request = w.DecStock t.Add Cancel = t.Empty || w.IncStock Buy = (t.Empty || w.SellCost) || c.deposit