Description

5/5 - (2 votes)

In this lab, you will be making a small class hierarchy for payment methods.  A payment method is responsible for charging some amount to an account or card. A charge can either be accepted (in which case funds are removed from associated object), or be declined (in which case the associated object should not be altered). The charge method should return true if the charge is accepted and false otherwise.  Again, no state should change in any object if the charge is not successful.

 

Before starting, make sure you understand the relationships between each object in the diagram below.  Think of which is composition, aggregation, and inheritance.  When you complete writing your classes, tell your TA which relationships are used and what parts of the code make you think that.  You will need to look at the driver to show one relationship.

 

The gift card has a pre-loaded amount supplied by the constructor.  A gift card can be charged as long as its balance remains non-negative and the charge is non-negative. A debit card does not have a pre- loaded amount, but is linked to an account. The debit card can be charged as long as the account associated with the debit card has a sufficient amount for the charge.  When depositing or with withdrawing from an account, the amount must be positive.  Hint, the DebitCard class should use some of the methods from the account class.  A driver has been provided with output below.

 

Image missing

 

Driver Output:

 

Test GiftCard Class

Balance of Gift Card is : $100.0

The gift card has been charged $200.00? It was unsuccessful. The gift card has been charged $-50.00? It was unsuccessful. The gift card has been charged $100.00? It was successful. Charging $100.00 again was unsuccessful.

The remaining balance of this Gift Card is $0.0

 

 

 

 

Test DebitCard Class

Current balance is: $0.0

Can I charge $200 to my debit card? Nope, you have no money.

Added money to my account linked to debit card.  Debit card has : $500.0

Can I charge -$2,000? Nope, amount was negative.  No free money today. Balance is: $500.0

Charging $1000 to this account was unsuccessful. Balance is: $500.0

Charging $100 to this account was successful. Balance is: $400.0

Charging $400 to this account was successful. Debit card balance is: $0.0

Depositing $8,000,000.00 to account.

Debitcard balance is now $8000000.0 and I am retiring.