Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Q1. Implement the following inheritance hierarchy: BankCard DebitCard Creditcard 1) The abstract class BankCard is the superclass of the hierarchy. It has two instance

image text in transcribed

java

Q1. Implement the following inheritance hierarchy: BankCard DebitCard Creditcard 1) The abstract class BankCard is the superclass of the hierarchy. It has two instance variables: name of the person (of type String) accountNo (of type int). It has a constructor that initializes the name and accountNo to the specified values. It has two methods: toString that returns the name and the Account number and two abstract methods deposit(double amount) and withdraw(double a 2 Class DebitCard is derived from BankCard. It has one instance variable: balance (of type double). It has a constructor that calls the superclass constructor to initialize the name, accountNo, and then it initializes balance to the specified values. It has three methods: a method deposit that implements the abstract method and add to the balance and a method withdraw that implements the abstract method it takes the amount to be withdrawn and compare it to the balance if it was less than the balance it will subtract it, else and returm true else it will return false, and a method toString that overrides the superclass version and returns the person's name, accountNumber and balance. Class CreditCard is derived from BankCard. It has two instance variable limit and balance (of type double). It has a constructor that calls the superclass constructor to nitialize the name, accountNo, and then it initializes the limit to the specified values. Balance is initialized by zero. It has three methods: a method deposit that implements the abstract method and subtract from the balance, a method withdraw that check if the amount + 2% of the amount is less than limit-balance if yes then adds the required amount + 2% of the amount to the balance and retum true else return false, a method with toString that overrides the superclass version and person's name, accountNumber and remaining limit (limit-balance) 4) Write a test class named BankCardTest that has a main method to test your classes. In the main method, create an array of references to BankCard objects, the array holds two instances of DebitCard object and two instances of a Credit object. You should create the objects first, the information are Account 0: Name: Ali, Type: Debit Card Account Number: 1234, Balance: 700 Account 1 Name: Yahya, Type: Credit Card, Account Number: 1235, Limit: 1000 Account 2 Name: Mohammed, Type: Credit Card, Account Number: 1254, Limit: 1000 Account 3: Name: Nour, Type: Debit Card, Account Number: 1256, Balance: 500 Then Prompt the user to perform 5 operations on the cards (using a loop). The user wil pick the index of the required card and you shall perform the required operation on it. Sample Output: Choose index of Card: 8 Enter operation type 1. Deposit 2. Withdraw: 1 Enter Amount: 200 Card is credited Ali, Account Number 1234, Balance: 9e8.8e Choose index of Card: 1 Enter operation type 1. Deposit 2. Withdraw: 2 Enter Amount: 2808 Card cannot be debited with this amount Yahya, Account Number 1235, Limit: 1800.e0 Choose index of Card: e Enter operation type 1. Deposit 2. Withdraw:2 Enter Amount: 388 Card is debited A??, Account Number 1234, Balance: 608.ee Choose index of Card: 2 Enter operation type 1. Deposit 2. Withdraw:2 Enter Amount: 100 Card is debited Mohanmed, Account Number 1254, Limit: 898.8e Choose index of Card: 2 Enter operation type 1. Deposit 2. Withdraw:1 Enter Amount: 180 Card is credited Mohanmed, Account Number 1254, Limit 998.88

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Have a brief review of human motivation theories

Answered: 1 week ago