You are on page 1of 3

Student Name Al Ain University

Student IDCollege of Engineering

Section

Student Name

Student ID

Section
Object-Oriented Programming
(0102221)
- Lab 03 -
Eng. Esra Al-Nashash

Student Name

Student ID

Section
Inheritance

✏Exercise: Bank Account Program

- Create a Base class called BankAccount.


- Create three data fields.
o String name // Account Holder’s Name , anyone can access it
o String accNum // Account Number only subclasses and this class can access it.
o Double Balance // Account Balance only this class can access it.
- Write setters and getters for class attributes.
- Write a default constructor to set account name to no name, accNum to no Number and
balance to 0.0.
- Write a constructor with three parameters and sets the class properties to those values.
- Write method called deposit that receive double amount and add this amount to the
balance, then print the new balance.
- Write method called withdraw that receives double amount and check if the balance is
enough it will subtract the amount from the balance and print the new balance, if not it
will display the message Sorry you don’t have enough Balance.
- Write to toString() method that return the account information in format of:
- Create a derived class called CheckingAccount.
- Create three private data fields.
o Integer checkCount // how many checks have been cashed this month
o Final double checkFee // 0.20 per check charge
o Final int freeChecks // 10 free checks
- Write a default constructor that calls the constructor of the superclass and set the
checkCount variable to 0.
- Write a constructor that takes four variables name, accNum, Balance, and checkCount
and sets the class properties to those values.
- Write setters and getters for class attributes.
- Override the method withdraw in the superclass to be able to count the checks done, if
checkCount is greater than freeCheck it will apply check fee for each extra check, or it
will print the number of free checks left.

- Create a test class called TestBankAccount.


- Create two objects, one from BankAccount class, and the other one from
CheckingAccount class.
- Use Class methods to deposit and withdraw amounts and display account information.

You might also like