274 views

Uploaded by Alimi Jasman

save

You are on page 1of 15

CASE STUDY

Software Engineering

Mike Wooldridge

COIN == {100. and 1 pence. we will give a complete specification of a vending machine – the sort you buy cans of coke or cigarettes from. 5. 2. 2. 50. the first one will be COIN.Lecture 16 Software Engineering 1 Specification of a Vending Machine • In this lecture. there are coins in denominations of 100. • First. 1} • That is. we need to introduce some types. 10. 20. • We will also need a type for system messages – this is parachuted in: [REPORT] Mike Wooldridge 1 . representing all the coins that are accepted by the machine. 5. 50. 20. 10.

Lecture 16 Software Engineering • Next. [PROD] • We can define the state space of the vending machine thus: VendingMachine cost : PROD → 7 IN stock : bag PROD float : bag COIN dom stock ⊆ dom cost Mike Wooldridge 2 . representing all the products that the machine can sell. we need a type PROD.

e. • QUESTION: Why are stock and float bags and not sets or sequences? • The invariant dom stock ⊆ dom cost says that everything in the machine (i. • The bag float records the coins that are currently in the machine. stock = {Penguin 7→ 2} means that there are just 2 penguins in the machine. for example float = {100 7→ 2. in stock) must have a cost associated with it. 8 × 50p coins and 20 × 5p coins. Mike Wooldridge 3 . For example. 5 7→ 20} means that there are 2 × £1 coins. cost(MarsBar) = 25 cost(Penguin) = 15 • The bag stock tells us how many items of each type are in stock.Lecture 16 Software Engineering • The function cost return the cost of a product in pence. For example. 50 7→ 8.

Mike Wooldridge 4 . • buying goods.Lecture 16 Software Engineering Operations Here are the operations we shall specify: • initialising the machine. • pricing goods. • restocking.

Lecture 16 Software Engineering Initialisation InitVendingMachine ∆VendingMachine cost0 = {} stock0 = [ ] float0 = [ ] • So initially. contains nothing. the machine does not know the cost of anything. and has no float. Mike Wooldridge 5 .

Lecture 16 Software Engineering Pricing Goods • This simply means changing the price of an item in stock. • The inputs are the item and a price. or pricing an item that is going to be stocked. Price ∆VendingMachine item? : PROD price? : IN cost0 = cost ⊕ {item? 7→ price?} stock0 = stock float0 = float Mike Wooldridge 6 .

Lecture 16 Software Engineering Restocking • The next operation to specify is that of restocking the machine with more goods. • The only input is a new bag of products.) Mike Wooldridge 7 . Restock ∆VendingMachine new? : bag PROD stock0 = stock ] new? float0 = float cost0 = cost • (Note that ] is the ‘bag union’ operator. • The precondition dom new? ⊆ dom cost is implied by the invariant of VendingMachine0.

GoodsNotPriced ΞVendingMachine new? : bag PROD rep! : REPORT ¬(dom new? ⊆ dom cost) rep! = ‘Some goods are not priced’ Mike Wooldridge 8 . We need a schema to identify this situation. The Restock operation fails when an attempt is made to add goods which are not priced.Lecture 16 Software Engineering • We shall now make the operation robust.

Lecture 16 Software Engineering • We need an operation to report success.. called RestockOp: d (Restock ∧ Success) RestockOP = ∨ GoodsNotPriced Mike Wooldridge 9 . we simply use the schema calculus to specify a robust version of the Restock operation.. Success rep! : REPORT rep! = ‘Okay’ • Now.

.Lecture 16 Software Engineering • This schema expands to .. RestockOp ∆VendingMachine new? : bag PROG rep! : REPORT cost0 = cost float0 = float (stock0 = stock ] new? ∧ rep! = ‘Okay’) ∨ (¬(dom new? ⊆ dom cost) ∧ stock0 = stock ∧ rep! = ‘Some goods are not priced’) Mike Wooldridge 10 .

• We have to check that the item is in stock.. • The inputs are the chosen item and some money.Lecture 16 Software Engineering Buying • The buying operation is a somewhat more complex operation .. Mike Wooldridge 11 ... • We may also have to figure out what change to give . and that the user has entered enough money to buy it.

5 7→ 3} = (2 × 7) + (5 × 3) = 14 + 15 = 29pence Mike Wooldridge 12 . and 3 × 5p coins. given a bag containing 7 × 2p. sum{2 7→ 7. which takes a bag of coins and calculates how much is in the bag. For example.Lecture 16 Software Engineering • We assume that a function sum : bag COIN → IN is available.

Lecture 16 Software Engineering • The basic Buy operation is as follows: Buy ∆VendingMachine in?. out! : bag COIN item? : PROD item? in stock sum(in?) ≥ cost(item?) out! v float sum(in?) = sum(out!) + cost(item?) stock0 ] {item? 7→ 1} = stock float0 ] out? = float ] in? cost0 = cost Mike Wooldridge 13 .

• the 4th condition says that the the money entered must equal the change given plus the cost of the item. • the 2nd condition says that the amount of money entered must be greater than or equal to the cost of the item. together with the change dispensed must equal the float before plus the amount entered (i. • the 6th condition says that the float after. no money disappears) Mike Wooldridge 14 .e. • the 3rd condition says that the change given must have been part of the float. • item? is the item dispensed to the user. to which is added the dispensed item.Lecture 16 Software Engineering • in? represents the coins entered. out! represents the change. • the 5th condition says that the stock before must be equal to the stock after. • the 1st condition says that the item must be in stock.

- Cs booksUploaded byDas Tribhubaneshwar
- Grade 9 Math Teacher39s GuideUploaded byMichele
- Views 3D ObjectsUploaded byMeriam EF Barreto
- srcd 15 postermathUploaded byapi-269876811
- Single Temperature Glass Front MerchandiserUploaded byGloriyajonathan112
- resume for ndfs 191Uploaded byapi-272471809
- The Manhood of HumanityUploaded byAgnieszka Brzezanska
- Streamwood Newsletter, September 2015Uploaded byscaddigan
- Part of Chapter 3 the Magic & Psychology of Numbers viki©Uploaded byviki
- interactive learning activitiesUploaded byapi-395297806
- Modern Trends in Airframe Structural Design KomarovUploaded byDebabrata Adhikari
- smart goal project self- evaluationUploaded byapi-272178501
- 86999_preffedUploaded byMuhammad Fachri
- jackie kim - term iii mathUploaded byapi-193684547
- Summer MathUploaded bybobbob698
- X CBSE 2016 Maths AnalysisUploaded byAnuj Kansal
- X CBSE 2016 Maths AnalysisUploaded byAnuj Kansal
- X-CBSE-2016-Maths-Analysis.pdfUploaded byPower Power
- Shift in PedagogyUploaded bypal_aarti41038
- Milan Mares reviewed the book "Fuzzy Cognitive Maps and Neutrosophic Cognitive Map", by W. B. Vasantha Kandasamy & F. SmarandacheUploaded byAnonymous 0U9j6BLllB
- SQL Tips and TricksUploaded byScott Lackey
- Lesson FiveUploaded byAlexandra Keresztes
- rebecca farrell recommendationUploaded byapi-239359115
- Musigma Sample Paper With ComputerUploaded byPranav Nagesh
- 9-23Uploaded byapi-301985021
- edu 1803 key terms 2017 1Uploaded byapi-370732305
- 9-23Uploaded byapi-301985021
- FSS BW Operations - Load Monitoring DocumentUploaded bykalicharan13
- volume lesson planUploaded byapi-279893616
- assignment 8Uploaded byapi-340409445

- Borang_1-Laporan_Penilaian.pdfUploaded byAlimi Jasman
- SOA EPU JPM.pdfUploaded byAlimi Jasman
- borang mpob.pdfUploaded byAlimi Jasman
- borang carian rasmi.pdfUploaded byAlimi Jasman
- Floor Plan ArchiUploaded byAlimi Jasman
- Senarai Pemohon Borang SPZB OnlineUploaded byAlimi Jasman
- Roof Plan ArchiUploaded byAlimi Jasman
- Borang Carian RasmiUploaded byAlimi Jasman
- Cer.Pro.BIM UTM KLUploaded byAlimi Jasman
- floor plan archi.pdfUploaded byAlimi Jasman
- i Great Medimax BrochureUploaded byAlimi Jasman
- i-great-medimax-brochure (1).pdfUploaded byAlimi Jasman
- Borang_1-Laporan_Penilaian.pdfUploaded byAlimi Jasman
- Borang Aduan Kerosakan UidmUploaded byAlimi Jasman
- Layout Plan Type 1Uploaded byAlimi Jasman
- Request for Surrender.pdfUploaded byAlimi Jasman
- 2014 Tsspk FormUploaded byAlimi Jasman
- Honda CityUploaded byAlimi Jasman
- 2014_tsspk-form.pdfUploaded byAlimi Jasman
- Parisien Tower LayoutUploaded byAlimi Jasman
- borang_ISBN.pdfUploaded byAlimi Jasman
- NaREC17 PosterUploaded byAlimi Jasman
- borang_uppt-1_pin_1-2016_f (1)Uploaded byAlimi Jasman
- Request for Surrender.pdfUploaded byAlimi Jasman
- Evolution of solid waste management in Malaysia.pdfUploaded byAlimi Jasman
- BNMNOTICEUploaded byAlimi Jasman
- 2014_tsspkUploaded byAlimi Jasman
- A Health Maximiser i BrochureUploaded byAlimi Jasman
- borang_ISBN.pdfUploaded byAlimi Jasman
- Syarat Starat Permohonan CcdUploaded byAlimi Jasman