|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.uci.ics.inf111.dvdvendor.app.DVDVendor
public class DVDVendor
The DVDVendor class contains the business logic of the point of sale, and keeps track of the state of the current customer's rental and return checkout. The class contains methods to handle renting DVDs and returning them.
Nested Class Summary | |
---|---|
static class |
DVDVendor.checkOutState
This enumeration represents the states of the DVDVendor system: READY means the system is awaiting a new customerStates for Rental: ADDING means the system is prepared for another item to be addedPAYING means the system is awaiting for paymentDISPENSING means the system is awaiting notification that the items
have been dispensed in the DVD DispenserStates for Returning: RECEIVING means the system is awaiting for the customer to return the product
using the DVD DispenserCALCULATING means the system is calculating the charges.Attempts to add items while PAYING or DISPENSING will result in errors. |
Field Summary | |
---|---|
private CheckOutCart |
checkOutCart
The cart containing items the customer has added. |
DVDDispenser |
dvdDispenser
The associated DVDDispenser, which will notify DVDVendor when it detects a status change. |
private PaymentCollector |
paymentCollector
An object representing the credit card or debit card accepting device. |
private ProductDB |
productDB
The database of products in the point of sale. |
private Transaction |
transaction
The transaction that will be persisted in the TransactionDB |
private TransactionDB |
transactionDB
The database of transactions in the point of sale. |
private DVDVendor.checkOutState |
transactionState
The current state of the system. |
Constructor Summary | |
---|---|
DVDVendor()
The argument-less constructor makes the necessary utility classes and passes them to the constructor with arguments. |
|
DVDVendor(DVDDispenser dvdDispenser,
PaymentCollector payment,
ProductDB productDB,
TransactionDB transactionDB)
This is the chief constructor. |
Method Summary | |
---|---|
Product |
addItem(BarCode barCode)
This method accepts a bar code and adds the corresponding product to the customer's cart. |
CheckOutCart |
calculateChargesForReturn(BarCode barCode)
This method calculate the charges for the Return Transaction. |
java.lang.String |
dispenseItems()
Method that dispense the items in the transaction using the dvdDispenser object from the dvdVendor object. |
DVDDispenser |
getDVDDispenser()
An accessor method which returns the DVDDispenser associated with this DVDVendor. |
PaymentCollector |
getPaymentCollector()
An accessor method which returns the PaymentCollector associated with this DVDVendor. |
ProductDB |
getProductDB()
An accessor method which returns the ProductDB associated with this DVDVendor. |
double |
getTotalCost()
This method returns the current total cost of all items in the cart. |
TransactionDB |
getTransactionDB()
An accessor method which returns the TransactionDB associated with this DVDVendor. |
DVDVendor.checkOutState |
getTransactionState()
An accessor method which returns the Transaction State Useful if the application wants to get the current state of the transaction. |
void |
initiateRental()
This method initiates a rental transaction |
void |
initiateReturn()
This method initiates a return transaction |
java.util.Enumeration<Product> |
listItemsInCart()
This method retrieves an enumeration of all the items currently in the cart and returns it. |
void |
notifyDVDDispenserEvent(DVDDispenser dd,
DVDDispenserEvent event)
When the DVDDispenser detects a change in its state, this function is called to change the state of the system (transactionState). |
CheckOutCart |
payForRental(java.lang.String cardNumber)
This method accepts a credit/debit card number to charge for the rented products. |
void |
receiveItem(java.lang.String barCode)
Method that receives the returned item using the dvdDispenser object from the dvdVendor object |
java.lang.String |
recordTransaction()
Method that records the transaction in the Transaction file |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private CheckOutCart checkOutCart
public DVDDispenser dvdDispenser
private PaymentCollector paymentCollector
private ProductDB productDB
private TransactionDB transactionDB
private DVDVendor.checkOutState transactionState
private Transaction transaction
Constructor Detail |
---|
public DVDVendor() throws java.lang.Exception
java.lang.Exception
public DVDVendor(DVDDispenser dvdDispenser, PaymentCollector payment, ProductDB productDB, TransactionDB transactionDB) throws java.lang.Exception
dvdDispenser
- dvdDispenser object for the DVDVendor.payment
- paymentCollector object for the DVDVendor.productDB
- productDB object for the DVDVendor.transactionDB
- transactionDB object for the DVDVendor.
java.lang.Exception
Method Detail |
---|
public void initiateRental() throws IncorrectStateException
IncorrectStateException
- Thrown when Rental was initiated when the system was not READYpublic void initiateReturn() throws IncorrectStateException
IncorrectStateException
- Thrown when Return was initiated when the system was not READYpublic Product addItem(BarCode barCode) throws InvalidProductException, IncorrectStateException, java.text.ParseException, TransactionDBException
barCode
- The bar code of the selected item.
InvalidProductException
- Thrown when a product corresponding to the bar code
is not found in the ProductDB
IncorrectStateException
- Thrown when the user tried to Add an item when the system
was in the state DISPENSING (AddWhileDispensingException) or PAYING (AddWhilePayingException).
TransactionDBException
- Thrown when there is an exception when looking for the
last transactions (rent and return) in which the barCode was involved
java.text.ParseException
- Thrown when there is an exception when invoking the method
getSecondsDifferencepublic CheckOutCart payForRental(java.lang.String cardNumber) throws PaymentCollectorException, IncorrectStateException
cardNumber
- String that represents the credit/debit card Number to be charged.
PaymentCollectorException
- Thrown if there was an error with the payment.
It could be that the cardNumber was not valid
IncorrectStateException
- Thrown if the user tried to pay when he/she did
not select items (PayWithNoItemsException), or when the payment was done while
dispensing (PayWhileDispensingException), or the incorrect type of
transaction was receivedpublic CheckOutCart calculateChargesForReturn(BarCode barCode) throws PaymentCollectorException, TransactionDBException, java.text.ParseException, IncorrectStateException
BarCode
- barCode object that identifies the product to be returned.
PaymentCollectorException
- Thrown if there was an error with the payment.
It could be that the cardNumber was not valid
TransactionDBException
- Thrown when there is an exception when looking for the
last transactions (rent and return) in which the barCode was involved
java.text.ParseException
- Thrown when there is an exception when invoking the method
getSecondsDifference
IncorrectStateException
- Thrown if the user tried to calculateCharges
when he/she did not select items (CalculateWithNoItemException), or when the
product has not been rented (ProductNotRentedException), or the incorrect type of
transaction was receivedpublic java.lang.String dispenseItems() throws IncorrectStateException, PersistenceException
IncorrectStateException
- Thrown if the dispense was done while adding
PersistenceException
- Thrown if there was an error in persisting
the transaction in the Transaction filepublic void receiveItem(java.lang.String barCode) throws java.lang.Exception
barCode
- String with the bar code of the returned item
java.lang.Exception
- Thrown if there are problem with the DVDDispenserpublic java.lang.String recordTransaction() throws PersistenceException
PersistenceException
- Thrown if there was an error in persisting
the transaction in the Transaction filepublic java.util.Enumeration<Product> listItemsInCart()
public double getTotalCost()
public void notifyDVDDispenserEvent(DVDDispenser dd, DVDDispenserEvent event)
notifyDVDDispenserEvent
in interface DVDDispenserListener
dd
- The attached DVDDispenser which is sending the event.event
- The DVDDispenserEvent, which includes the type of event
and the read bar code.public DVDDispenser getDVDDispenser()
public ProductDB getProductDB()
public TransactionDB getTransactionDB()
public PaymentCollector getPaymentCollector()
public DVDVendor.checkOutState getTransactionState()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |