Assignment
3 - Widget Trading
Due Tuesday, April 27
A
widget store starts with a 100 widgets and no dollars. The widget store sells a
widget using the formula:
price
in dollars = round[101/(number of widgets currently owned by the store + 1)]
When
selling N widgets in a single transaction, each widget is the same price as the
first widget of the transaction. If the store has 100 widgets, buying 2 widgets
at once will cost a total of $2. When buying widgets the store will pay
round[101/(number of widgets currently owned by the store + 3)] dollars per
widget. In a multi-widget deal the store uses the price of the first widget as
the price for each widget. When buying widgets the store can not pay money more
than the store has. A store object has a currentSellPrice method, a
currentBuyPrice method, a buy method and a sell method. You can add more
methods as needed.
A
customer starts with 25 dollars and no widgets. A customer will contact the
widget store to purchase.
Write a widget store Jini service. The service will have one store. The store
is to be activatable. The store maintains its state (number of widgets and
number of dollars) between invocations of the server process. The store service
should also always use the same service ID each time it registers with any Jini
lookup service. Test your widget store by having some customers contact the
store (in client programs), buy some widgets and then sell 1/2 of the widgets
back to the store. The remote stubs for the store service should be dynamically
downloaded to the client customer program.
Improve the store buy allowing customers to register as remote listeners of the
price of a widget. The customer is to be informed when the price of a widget
changes. (You could have a customer register in knowing when the price of a
widget goes above a given price. This is a bit harder, and is optional). Write
a customer object that buys some widgets and registers itself to be informed of
changes in widget prices. When the widget buy-back price is 10 dollars more
than the price the paid for a widget, a customer sells the widgets back to the
store. Make sure that your remote listeners are leased.
Improve
your store by using the transaction manager to conduct the widget transaction
between the store and customers.