Question: (In Java) public class Lab8_Driver { public static void main(String[] args) { // test gift card System.out.println(Test GiftCard Class ); GiftCard giftCard = new GiftCard(500);

(In Java)(In Java) public class Lab8_Driver { public static void main(String[] args) {// test gift card System.out.println("Test GiftCard Class "); GiftCard giftCard = new

public class Lab8_Driver {

public static void main(String[] args) {

// test gift card System.out.println("Test GiftCard Class "); GiftCard giftCard = new GiftCard(500); System.out.println("Balance of Gift Card is : $" + giftCard.getBalance()); System.out.print("The gift card has been charged about $600.00? "); if (giftCard.charge(600)) { System.out.println("successful. ");

} else System.out.println("unsuccessful. ");

System.out.print("The gift card has been charged about $200.00? "); if (giftCard.charge(200)) { System.out.println("successful. ");

} else System.out.println("unsuccessful. ");

System.out.println("The remaining balance of this Gift Card is $" + giftCard.getBalance());

System.out.print(" ");

// test account System.out.println("Test Account Class"); Account a = new Account(); System.out.println("Balance of new created account is : $" + a.getBalance()); System.out.print("Withdraw $100 from this account was "); if (a.canWithdraw(100)) { System.out.println("successful. ");

} else System.out.println("unsuccessful. ");

System.out.println("The new balance is $" + a.getBalance()); a.deposit(200); System.out.println("Deposit $200 to this account is done. "); System.out.println("The new balance is $" + a.getBalance()); a.deposit(500); System.out.println("Deposit $500 to this account is done. "); System.out.println("The new balance is $" + a.getBalance());

// test DebitCard System.out.println(" "); System.out.println("Test DebitCard Class"); DebitCard d = new DebitCard(a); System.out.println("The new debit card is issued for perivous account. "); System.out.println("New debitcard balance is : $" + d.getAccount().getBalance()); System.out.print("Withdraw $100 from this account was "); if (d.charge(100)) { System.out.println("successful. ");

} else System.out.println("unsuccessful. "); System.out.println("Debitcard balance is now : $" + d.getAccount().getBalance()); System.out.print("Withdraw $9000 from this account was "); if (d.charge(9000)) { System.out.println("successful. ");

} else System.out.println("unsuccessful. "); System.out.println("Debitcard balance is now : $" + d.getAccount().getBalance()); System.out.println("Deposit $800 to this account was successful"); d.getAccount().deposit(800); System.out.println("Debitcard balance is now : $" + d.getAccount().getBalance());

}

}

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!