Exercises
Exercises
Design an abstract class called “BankAccount” that declares an abstract method “withdraw(double
amount)” and has data members “accountNumber (String)” and “balance (double)”. Include a concrete
method “deposit(double amount)” that adds to the balance.
Create two concrete subclasses: “SavingsAccount” that prevents withdrawals exceeding the balance, and
“CheckingAccount” that allows overdrafts up to $500. Both should implement “withdraw()”
appropriately. Do not forget to implement a parameterized constructor and proper set/get methods.
a) Create a list containing one SavingsAccount and one CheckingAccount with initial balances.
b) Demonstrate polymorphism by processing withdrawals from both account types. Get the withdrawal
amount from the user.
c) Create a custom exception InsufficientFundsException and throw and catch when withdrawals fail.
Create three concrete subclasses, do not forget to implement a parameterized constructor and proper
set/get methods:
In main():
Create interfaces:
Implement three classes; do not forget to implement a parameterized constructor and proper set/get
methods:
In main():