HOMEWORK ASSIGNMENT #1
CS 586; Spring 2023
Due Date: February 9, 2023
Late homework 50% off
After 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 submission
must 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 the
Book Market. This class supports the following operations: SetPrice(ISBN,price),
GetPrice(ISBN), BuyBook(ISBN), SellBook(ISBN), and NumBooks(ISBN). The
SetPrice(ISBN,price) operation set a new price for the book uniquely identified by ISBN. The
GetPrice(ISBN) operation returns the current price of the book identified by ISBN. The
BuyBook(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 the
number of copies of a book identified by ISBN that are available in the system. Notice that each
book is uniquely identified by ISBN.
In addition, there exist user components in the system (e.g., UserA, UserB, etc.) that are
interested in watching the changes in book prices, especially, they are interested in watching the
out-of-range book price changes. Specifically, interested users may register with the system to be
notified when the price of the book of interest falls outside of the specified price range. During
registration, the user needs to provide the boundaries (lowprice, highprice) for the price range for
the specific book, where, lowprice is the lower book price and highprice is the upper book price
of the price range. At any time users may un-register when they are not interested any longer in
watching the out-of-range book price changes of a specific book. Each time when the price of a
book changes, the system notifies all registered users (for which the new book price is outside of
the specified price range) about the out-of-range book price change. Notice that if the book price
change is within the specified price range for a given user, this user is not notified about this
price 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 that
should include classes BookSystem, UserA, and UserB (if necessary introduce new classes and
operations). 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 components
in your design should be de-coupled as much as possible. In addition, components should have
high cohesion.
In your solution:
a. Provide a class diagram for the system. For each class list all operations with parameters and
specify them using pseudo-code. In addition, for each class provide its attributes/data
structures. 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 price
change.
How the system notifies the registered user component about the out-of-range book
price change.
PROBLEM #2 (60 points)
The ATM component supports the following operations:
create() // ATM is created
card (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 d
withdraw (int w); // withdraw amount w
balance (); // display the current balance
lock(string x) // lock the ATM, where x is a pin #
unlock(string x) // unlock the ATM, where x is pin #
exit() // exit from the ATM
A 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 pattern
Notice that the components in your design should be de-coupled as much as possible. In
addition, components should have high cohesion.
For each solution:
a. Provide a class diagram for the system. For each class list all operations with parameters and
specify them using pseudo-code. In addition, for each class provide its attributes and data
structures. Make the necessary assumptions for your design.
b. Provide a sequence diagram for the following operation sequence:
create(), card(900,”abc”), pin(“abc”), deposit(300), withdraw(110), exit()
When the EFSM model is “executed” on this sequence of operations, the following sequence
of transitions is traversed/executed: T1, T2, T19, T14, T7, T5
check pin
ready
overdrawn
idle
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 b
withdraw( 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 b
exit / eject card
lock( x )[ x==pn ]
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。