1 57 58 package shop; 59 60 import java.util.*; 61 65 public class ShoppingCart_Java { 66 private int fieldTotal = 0; 67 68 private String fieldFirstName; 69 private String fieldLastName; 70 private Address fieldAddress; 71 private String fieldCustomerNumber; 72 73 private Order fieldOrder; 74 75 private static Orders fieldAllOrders = new Orders(); 76 77 public ShoppingCart_Java() { 78 super(); 79 } 80 81 public ShoppingCart_Java( 82 String firstName, 83 String lastName, 84 Address address, 85 String customerNumber) 86 throws CreateException { 87 super(); 88 89 fieldFirstName = firstName; 90 fieldLastName = lastName; 91 fieldAddress = address; 92 fieldCustomerNumber = customerNumber; 93 94 fieldOrder = new Order(customerNumber); 95 } 96 97 public int addItem( 98 String itemNumber, 99 Item item, 100 String itemName, 101 int itemQuantity) 102 throws InvalidItemException, OutOfStockException { 103 if (itemQuantity > 10) 104 throw new OutOfStockException( 105 "There are less then '" 106 + itemQuantity 107 + "' pieces of '" 108 + itemName 109 + "' in stock"); 110 111 if ((itemNumber == null) 112 || (itemName == null) 113 || (itemNumber.equals("")) 114 || (itemName.equals(""))) 115 throw new InvalidItemException( 116 "Invalid item: Number = '" + itemNumber + "' Name = '" + itemName + "'"); 117 118 item.setNumber(itemNumber); 119 item.setName(itemName); 120 item.setQuantity(itemQuantity); 121 item.setPrice(100); 123 fieldOrder.addItem(itemNumber, item); 124 125 fieldTotal += (item.getPrice()*item.getQuantity()); 126 127 return fieldTotal; 128 } 129 130 public static Orders queryOrders(String customerNumber) 131 throws EmptyResultException { 132 return fieldAllOrders.getOrders(customerNumber); 133 } 134 135 public void emptyOrder(String customerNumber) 136 { 137 fieldOrder.empty(); 138 fieldTotal = 0; 139 } 140 141 public long submitOrder( 142 CreditCardInfo creditCardInfo, 143 AirMilesContainer airMilesContainer) { 144 long orderConfirmationNumber = System.currentTimeMillis(); 145 fieldOrder.setConfirmationNumber(orderConfirmationNumber); 146 fieldAllOrders.add(fieldOrder); 147 fieldOrder = null; 148 airMilesContainer.addMiles(1000); 149 return orderConfirmationNumber; 150 } 151 } 152 | Popular Tags |