CS 401 Intermediate Programming Using Java
Project 3
Info
| Posted: | Wednesday, July 12th, 2006 |
| Due Date: | Friday, July 28th, 2006 |
| Late Due Date: | Monday, July 31st, 2006 |
Idea
You want to give the customers of your online store an easier and more
interactive experience. You decide to design and implement a Graphical User
Interface to replace the text and command line based interface your customers
have been using thus far.
Assignment
Write a Java event driven application for your online store from project 2.
Your application must do the following:
- Read the same input file from project 2 having the same format, which is
reprinted below for convenience.
- Display a window with a well designed graphical user interface for the online store.
- For each inventory item in the store, the GUI must display:
- the product name
- The price of the product
- a JTextField in which the user will enter the quantity he or she
would like to purchase
- a subtotal for each item as a JLabel which displays the price times
the entered quantity minus a discount
- a JButton that, when clicked, displays a popup window describing a
discount for the item, if there is one
- Around the collection of inventory items displayed should be a border
with a title
- Displays information for the overall
transaction, which includes:
- an overall subtotal that is updated with each change in item
quantities
- the amount of the discount for the entire transaction (if
there is no discount, this should not be displayed)
- the amount of any tax that is added to the sale. We'll assume that
all users live in PA.
- A final total for the transaction
- (The tax and total should not be updated until the user checks out)
- Displays a Checkout button that, when clicked, prevents the user
from changing the item quantities, calculates and displays the transaction
discount, tax, and final total, enables the credit card field, and disables
itself.
- Displays a JTextField to allow the user to enter his credit card number.
For each customer, this should be initially disabled until the user clicks
the checkout button. When the user enters his credit card number and hits
the enter key, it should become disabled and the next customer button should
become active.
- Displays a Next Customer button that's initially disabled. Once
the user completes the transaction by entering his credit card number, this
button should become enabled. When clicked, it should clear the transaction
from the screen setting the subtotals back to zero, enabling the quantity
fields and checkout button again, and disabling itself
- Displays a Quit Button that is always enabled and allows the user to
terminate the application as an alternative to clicking the close box on the
window.
- If the user enters a quantity greater than the available quantity in the
inventory, a dialog box indicating the problem should appear, and the
quantity entered should be reduced to the number of available items.
- If any of the items have no units left in inventory, the
corresponding JTextField should be permanently disabled.
Details
- The input file name should be a command line argument again as in the
last project.
- The same discount and inventory item assumptions apply from project 2.
Input File Format
The input file that your program reads must have the following format:
- Any line starting with a '#' character is considered a comment and
ignored
- The first line (that's not a comment line or empty line) is a integer indicating the
number of products
Each of the next set lines represents a product in your store with its
inventory count, price, and discount with the following format:
<The Product Name>@<Inventory Count>@<Price Per Unit>@<Discount>
Since the product name could contain spaces, each of our tokens in the
line will be delimited by the '@' character. Note that the <> characters
denote a token and should not be included in the actual file. Also, the
<Discount> portion of the line will be structured based on the type of
discount in general as: typeNum@X@Y@
For type 2, if the first character of Y is a space, then a flat discount
of Y is applied. If the first character is instead a '%', then Y is still a
dollar amount that should be discounts PER ITEM purchased.
If typeNum is zero, then there is no discount for the
product
- The last line in the file represents a single discount that can be
applied to an entire user transaction. It will be formatted as any other
discount.
Example Input File for products from first lab:
#-----------------------------------------------------------------
# CS401 Project 2 Example Input File
#
#-----------------------------------------------------------------
#Four products
4
#We have 300 Sunglasses at $50 with no discount
Sunglasses@300@50.00@0@
#DVDs have a type 2 discount of buy 5 or more, get $5 off per item
Matrix DVD@400@20.00@2@5@%5.00@
#
# Ignore comment lines and any empty lines
#
Neo Overcoat@10@250.00@0@
#
# Hover pads have a type 1 discount of buy 3, get 1 free
#
Hover Pad@20@4000000.00@1@3@1@
#
# Lastly, we have a type 3 discount of 10% if the purchase exceeds $500
#
3@500.00@0.1@
Notes and Hints
- Sketch the layout of your components on paper first
- It might be useful to create one or more helper methods that put your
GUI components in a certain state and can be called from different event
handlers.
- Implementing the GUI is almost completely independent from the rest of
the program (This is not a requirement, though)
- You can probably copy and paste
Extra Credit
For those interested in extra credit, you can implement some of the following
and, as always, if you have another idea, first clear it with me:
- From project 1, when the user enters his credit card number, you can
check a list of stolen credit cards. If the card matches a stolen number,
display a dialog window indicating such. The list of stolen numbers must
initially come from a file but must be stored in some type of Collection.
Deciding the correct type of Collection will get you more points.
- Newer GUIs have embedded clickable hyperlinks, and Java supports this.
Instead of having an extra button that displays the popup dialog with
Discount information, turn the product name or price into a hyperlink that
when clicked performs the same action.
- Having to hit the enter key when entering item quantities can be
annoying for the user. Find an alternative.
- Design for multiple and even overlapping discounts per item or for the
entire transaction.