在该系统中,存在一个类BookSystem,它跟踪图书市场。此类支持以下操作:SetPrice(ISBN,price),GetPrice(ISBN)、BuyBook。这个SetPrice(ISBN,price)操作为ISBN唯一标识的图书设置新价格。这个GetPrice(ISBN)操作返回由ISBN标识的图书的当前价格。这个BuyBook(ISBN)操作用于购买由ISBN标识的图书。畅销(ISBN)操作用于销售由ISBN标识的图书。操作NumBooks(ISBN)返回系统中可用的ISBN标识的书籍的副本数。请注意,每个这本书是由ISBN唯一标识的。此外,系统中存在以下用户组件(例如,UserA、UserB等)有兴趣观察图书价格的变化,尤其是,他们有兴趣观察超出范围的图书价格变化。具体而言,感兴趣的用户可以向系统注册当权益书的价格落在指定的价格范围之外时通知。在期间注册时,用户需要提供价格范围的边界(低价、高价)具体的书籍,其中,低价是较低的书籍价格,高价是较高的书籍价格价格范围内。当用户不再感兴趣时,可以随时取消注册观察特定书籍的超出范围的书籍价格变化。每次书籍更改时,系统会通知所有注册用户(新书价格不在指定的价格范围)。
CS 586; Spring 2023Due Date: February 9, 2023Late homework 50% offAfter February 13, the homework assignment will not be accepted.This is an individual assignment. Identical or similar solutions will be penalized.Submission: All homework assignments must be submitted on the Blackboard. The submissionmust be as one PDF-file (otherwise, a 10% penalty will be applied).PROBLEM #1 (40 points)
In the system, there exists a class BookSystem which keeps track of the prices of books in theBook Market. This class supports the following operations: SetPrice(ISBN,price),GetPrice(ISBN), BuyBook(ISBN), SellBook(ISBN), and NumBooks(ISBN).TheSetPrice(ISBN,price) operation set a new price for the book uniquely identified by ISBN. TheGetPrice(ISBN) operation returns the current price of the book identified by ISBN. TheBuyBook(ISBN) operation is used to buy a book identified by ISBN. The SellBook(ISBN)operation is used to sell a book identified by ISBN. The operation NumBooks(ISBN) returns thenumber of copies of a book identified by ISBN that are available in the system. Notice that eachbook is uniquely identified by ISBN.In addition, there exist user components

1.System

that areinterested in watching the changes in book prices, especially, they are interested in watching theout-of-range book price changes. Specifically, interested users may register with the system to benotified when the price of the book of interest falls outside of the specified price range. Duringregistration, the user needs to provide the boundaries (lowprice, highprice) for the price range forthe specific book, where, lowprice is the lower book price and highprice is the upper book priceof the price range. At any time users may un-register when they are not interested any longer inwatching the out-of-range book price changes of a specific book. Each time when the price of abook changes, the system notifies all registered users (for which the new book price is outside ofthe specified price range) about the out-of-range book price change. Notice that if the book pricechange is within the specified price range for a given user, this user is not notified about thisprice change.

BookSystem
List:<ISBN,price,num>
SetPrice( )
GetPrice( )
BuyBook( )
SellBook()
NumBooks()
User A
DisplayPrice( )
User B
DisplayPrice( )

Design the system using the Observer pattern. Provide a class diagram for the system thatshould include classes BookSystem, UserA, and UserB (if necessary introduce new classes andoperations). In your design, it should be easy to introduce new types of user components (e.g.,UserC) that are interested in observing the changing prices of books. Notice that the componentsin your design should be de-coupled as much as possible. In addition, components should havehigh cohesion.

2.In your solution:

a. Provide a class diagram for the system. For each class list all operations with parameters andspecify them using pseudo-code. In addition, for each class provide its attributes/datastructures. Make the necessary assumptions for your design.b. Provide two sequence diagrams showing: How a user component registers to be notified about the out-of-range book pricechange. How the system notifies the registered user component about the out-of-range bookprice change.
PROBLEM #2 (60 points)The ATM component supports the following operations:create() // ATM is createdcard (int x, string y) //ATM card is inserted where x is a balance and y is a pin #pin (string x) // provides pin #deposit (int d); // deposit amount dwithdraw (int w); // withdraw amount wbalance (); // display the current balancelock(string x) // lock the ATM, where x is a pin#unlock(string x) // unlock the ATM, where x is pin #exit() // exit from the ATMA simplified EFSM model for the ATM component is shown on the next page.Design the system using the State design pattern. Provide two solutions: a decentralized version of the State pattern a centralized version of the State patternNotice that the components in your design should be de-coupled as much as possible. Inaddition, components should have high cohesion.For each solution:a. Provide a class diagram for the system. For each class list all operations with parameters andspecify them using pseudo-code. In addition, for each class provide its attributes and datastructures. Make the necessary assumptions for your design.b. Provide a sequence diagram for the following operation sequence:create(), card(9n this sequence of operations, the following sequenceof transitionsistraversed/executed: T1, T2, T19, T14, T7, T5check pinreadyoverdrawnidle

pin( x )[ (x==pn)&&(b>=1000) ] /display menu
pin( x )[ (x!=pn)&&(attempts==3) ] /eject card
pin( x )[ (x!=pn)&&(attempts<3) ] /attempts++
pin( x )[ (x==pn)&&(b<1000) ] /display menu
locked
unlock( x )[ (x==pn)&&(b<1000) ]unlock( x )[ (x==pn)&&(b>=1000)EFSM of ATM
card( x, y ) / b=x; pn=y;attempts=0
create
balance / display balance bwithdraw( w )[ b-w>=1000 ] /b=b-w
deposit( d ) / b=b+d
withdraw( w )[ (b-w<1000)&&(b-w>0) ] /b=b-w-10
exit / eject card lock( x )[ x==pn ]deposit( d )[ b+d>=1000 ] /b=b+d
deposit( d )[ b+d<1000 ]
/ b=b+d-10
balance / display balance bexit / eject card
lock( x )[ x==pn ]

WX:codehelp


玩滑板的松鼠
1 声望0 粉丝