首页 > > 详细

CSC B07辅导、Java程序设计辅导

CSC B07 Software Design
Exercise 3
1 Logistics
Due date: 11:59pm Thursday 19 November 2015
Group size: Individual
Topics: Design Patterns
For the rules and procedures for the exercises, including how to submit, please see the Exercises page of the
course website.
2 What to do for this exercise
1. Your individual svn repository now contains a new directory called E3. It contains the starter code for
this exercise. Checkout and study the starter code.
2. Complete/implement Java classes Product, Shopper, and PriceWatchWebsite that obey the specifi-
cations below and the descriptions in the starter code.
3. To submit your work, add and commit your changes to your repository.
Do not commit the files and directories generated by Eclipse, such as bin, doc, .project, etc. Marks
will be deducted if you submit these.
3 Specifications for Product, Shopper, and PriceWatchWebsite
Your task is to implement Product, Shopper, and PriceWatchWebsite classes.
3.1 Class Product
A Product has a name, a price, and a store. Class Product is an Observable and has these methods:
A constructor.
Getters for name, price, and store.
A method changePrice that changes the price of a Product and notifies all its observers. Hint: Think
carefully of how you can use the class PriceChange provided in the starter code.
A method toString that returns a String of the form:
PRODUCT at STORE costs PRICE.\n
where PRODUCT, PRICE, and STORE are the name, price, and store of the product. In the return String,
the price should be formatted to 2 decimal places. Here is an example of formatting a string in Java
(see documentation for String.format):
String priceFormatted = String.format("%s costs %.2f", name, price);
1
3.2 Class Shopper
A Shopper has a name. Class Shopper is an Observer and has these methods:
A constructor.
A getter for name.
An update method that prints a message when a Product that the Shopper is observing changes. The
message is of the form:
SHOPPER: price change of PRODUCT on DATE at STORE to PRICE.\n
where SHOPPER, PRODUCT, DATE, STORE, and PRICE are the shopper’s name, product’s name, date and
time of price change, store, and new price (to 2 decimal places). Note that DATE is the date and
time when the price change occurred, not when this information was received by Shopper.
DATE should be formatted according to the standard described in the documentation of
Java class Date. Hint: Think carefully of how you can use the class PriceChange provided in the starter
code.
3.3 Class PriceWatchWebsite
A PriceWatchWebsite has a URL. Class PriceWatchWebsite is an Observer and an Observable, and has
these methods:
A constructor.
A getter for URL.
A method update that prints a message when an object that the website is observing changes. The
message is of the form:
You are subscribed to URL.
Price change of PRODUCT on DATE at STORE to PRICE.\n
where URL, PRODUCT, DATE, STORE, and PRICE are the website’s url, product’s name, date and time of
price change, store, and new price (to 2 decimal places) respectively. DATE is formatted exactly as
described above.
This method also notifies its observers of the change.
4 Checklist
Have you. . .
tested your code on the lab computers using Java 1.7?
run checkstyle on all of your code?
committed the correct files in the correct directory?
verified that your changes were committed using svn list and svn status?
checked the pre-marking results, made any necessary changes, and re-committed if necessary?

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!