Java Reference
In-Depth Information
LISTING 6.4
The Full Text of GiftShop.java
1: import org.cadenhead.ecommerce.*;
2:
3: public class GiftShop {
4: public static void main(String[] arguments) {
5: Storefront store = new Storefront();
6: store.addItem(“C01”, “MUG”, “9.99”, “150”);
7: store.addItem(“C02”, “LG MUG”, “12.99”, “82”);
8: store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
9: store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
10: store.sort();
11:
12: for (int i = 0; i < store.getSize(); i++) {
13: Item show = (Item)store.getItem(i);
14: System.out.println(“\nItem ID: “ + show.getId() +
15: “\nName: “ + show.getName() +
16: “\nRetail Price: $” + show.getRetail() +
17: “\nPrice: $” + show.getPrice() +
18: “\nQuantity: “ + show.getQuantity());
19: }
20: }
21: }
This application uses the org.cadenhead.ecommerce package but does not belong to it.
The GiftShop class demonstrates each part of the public interface that the Storefront
and Item classes make available. You can do each of the following:
Create an online store
n
Add items to it
n
Sort the items by sale price
n
Loop through a list of items to display information about each one
n
CAUTION
If you have stored Item.class , Storefront.class , or their source
code files in the same folder as GiftShop.java , you might not be
able to compile the program because the Java compiler expects to
find those files in their package folder. Move those files to the
org\cadenhead\ecommerce folder and compile GiftShop.java in
another folder, such as \J21work .
 
Search WWH ::




Custom Search