Homework 3
CS320, Spring 2004
Due: Wednesday April 28
Please upload your servlet class
files to your ~/public_html/WEB-INF/classes
directory on the server
cs.calstatela.edu, and send
the URL
to the Shop servlet,
presumably http://cs.calstatela.edu:8280/~username/servlet/Shop,
to csun@calstatela.edu. Please
also include the servlet java
files and the text files from Ex.1 in the email as attachments.
Make
sure
to use CS320
Spring 04 HW3 as the subject of the email, and include in the
email
your name so I don't have to guess names from
email addresses.
1. [Products] (10pt) Now it is time to populate your online store
with some product information. The requirements regarding the product
from Homework 1 still hold, and in addition:
- Each product category must have at least 10 items.
- Each product category must have one additional attribute Quantity, which shows the quantity
of an item currently in stock. At least one item in a category must
have 0 in Quantitiy,
indicating that item is out of stock.
- At least one item in a category must have a NULL field,
indicating that the information about that attribute of the item is
currently unavailable for whatever reason.
Store your product information in a text file or multiple text files.
The format of the file is entirely up to you. However, considering that
in later assignments you'll need to import the
file(s) into a MySQL database, it might be easier to use a
tab-delimited format. For example, suppose I have the following
categories/attributes for my product:
CPU
|
ProductID, Brand, Frequency,
Price, Quantity
|
Motherboard
|
ProductID, Brand, Chipset,
Description, Price, Quantity
|
Hard Drive
|
ProductID, Brand, Size, RPM,
InterfaceType, Price, Quantity
|
I'll have three files cpu.txt,
motherboard.txt, and harddrive.txt. The file cpu.txt would look like the
following
ProductID\tBrand\tFrequency\tPrice\tQuantity
CPU-001001\tIntel Pentium 4\t2.8 GHz\t248\t10
CPU-001201\tIntel Pentium 4\t3.0 GHz\t300\t0
... ...
CPU-00200\tNULL\t0.8 GHz\t45\t1
CPU-00235\tAMD AthlonXP\t3.0 GHz\t200\5
2. [Servlet] Write a Java servlet Shop.java which provides the
following functions:
- Initialization (10pt). When the servlet is first started, it
loads data from the text files prepared in the first part of this
assignment. I'll refere to the data structure holding the data in
memory as a Table, and how to
implement such a Table is up
to you.
- Search and Browse (20pt). When a user first visits http://cs.calstatela.edu:8280/~username/servlet/Shop,
the servlet should show an interface which consists of
- A drop-down list of the categories.
- An input field for a search string.
- Two buttons which are labeled as Search and Browse, respectively.
When a user click on the Search button,
the servlet should display all items in the Table under the selected category
which match the search string. An item matches a search string if any
attribute of the item contains the search string as a substring,
case-insensitive. When a user click on the Browse button, the servlet
should display all items under the selected category.
- Display (20pt). The items result from a Search or a Browse
operation should be displayed in a table, and
- For each item that is in stock, there is a Buy button
associated it. When a user click on a Buy button, the item associated
with that button is added to a Shopping Cart, and the servlet will
display the current content of the shopping cart.
- Set the max number of items can be displayed in one page to be
8. If the items matching a search string cannot be display in one page,
add a Next button, which when pressed, will display the rest of the
matching items.
- Shopping Cart (20pt). Display the items currently in the shopping
cart together with three buttons:
- Clear Shopping Cart button, which clears the content of the
shopping cart.
- Continue Shopping button, which will bring the user back to the
Search and Browse interface.
- Make Purchase button, which will end the session, and bring the
user back to the Search and Browse interface.