Question: JAVA In this lab, you will be making a small class hierarchy for payment methods. A payment method is responsible for charging some amount to
JAVA
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 debt is added or funds are removed from an 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 implementation, identify the type of object relationship in the diagram below (there are three). Categorize the relationship into inheritance, aggregation, and composition. Explain your choice to your lab instructor before you are checked off.
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. A debit card does not have a pre-loaded amount, but is linked to a bank account. The debit card can be charged as long as the bank account has a sufficient amount for the charge.
Once again you are responsible for writing a small test driver to show that your code works in some common cases. You should write the driver as a small scenario that a user is likely to enocunter. You do not need to utilize user input for the driver.
| > PaymentMethod |
| + charge(amount: double): boolean |
| GiftCard |
| - balance: double |
| + GiftCard(balance: double) + getBalance(): double + charge(amount: double): boolean |
| DebitCard |
| - account: Account |
| + DebitCard(account: Account) + getAccount(): Account + charge(amount: double): boolean |
| Account |
| - balance: double = 0 |
| + getBalance(): double + canWithdraw(amount: double): boolean + withdraw(amount: double) + deposit(amount: double) |


public class Lab8 Driver public static void mainCString0 args) test gift card System. out rintin Test Gift Card Class Giftcard giftcard new Gift CardC500); System. out. rintln("Balance of Gift Card is gift card. getBalanceO); System. out.print The gift card has been charged about $600.00? if CgiftCard.chargeC600)) System. out successful "D; else System. out. rintlnC unsuccessful System. out The gift card has been charged about $200.00? if CgiftCard. charge 200 System. out. rintlnC successful else System. out. printlnC"unsuccessful. System. out.printlnC The remaining balance of this Gift Card is giftCard.getBalanceO); System out print "InNn test account System. out.printlnC Test Account Class Account a new AccountO System out print "Balance of new created account is a.getBalanceO); System. out rint Withdraw $100 from this account was if Ca.canWithdraw(1000) System. out.println( successful else System. out. printlnC"unsuccessful. System. out. p rintln("The new balance is a.getBalance deposit 200 System out print inC Deposit $200 to this account is done System. out rintln("The new balance is a.getBalanceO); a deposit(500); System. out.printlnC Deposit $500 to this account is done System. out.printlnC The new balance is a.getBalanceO); test Debit Card System.out. printin("An "); System. out.println("Test DebitCard Class Debit Card d new Debit CardCa) System out print "The new debit card is issued for perivous account System. out. printin C"New debit card balance is d.getAccountO.getBalanceO); System. out. p ("Withdraw $100 from this account was rint if (d.charge(100)) System. out. rintlnC successful else System. out.p unsuccessful rintlnC System. out. p rintlnC"Debitcard balance is now d.get Account O.getBalance System. out.printC "Withdraw $9000 from this account was if Cd.charge C9000)) System out.printlnC successful h else System. out rintlnC unsuccessful System. out. printin Debitcard balance is now d.getAccountCD.getBalance System. out $800 to this account was successful d. getAccountO .deposit(800); System. out.printlnC"Debitcard balance is now d get Account O.getBalance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
