0% found this document useful (0 votes)
30 views3 pages

Assignment

Uploaded by

rathodnehanshu4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Assignment

Uploaded by

rathodnehanshu4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Question: Build a Simple Banking System in Java with Object-Oriented Concepts

You are tasked with creating a console-based banking system that allows users to
perform basic banking operations. This exercise will test your understanding of object-
oriented programming (OOP) principles, including static variables/methods, abstract
classes, inheritance, and polymorphism. The system will have different types of bank
accounts, and it will track the total number of accounts created.

1. Abstract Class:
Create an abstract class `BankAccount` that serves as a blueprint for different types of
bank accounts:
- Attributes: `accountNumber` (integer) and `balance` (double).
- Methods:
- `deposit(double amount)`: Adds the specified amount to the balance.
- `withdraw(double amount)`: Deducts the specified amount from the balance (if
sufficient).
- `checkBalance()`: Displays the current balance.
- `abstract void calculateInterest()`: An abstract method that will be implemented by
child classes to calculate interest for different account types.

2. Concrete Classes:
Create two concrete classes that extend `BankAccount`:
- SavingsAccount: Implements the `calculateInterest()` method to add interest (3%) to
the balance.
- CurrentAccount: Implements the `calculateInterest()` display a message indicating no
interest.

3. Static Fields and Methods:


In a `Bank` class, use a static variable `totalAccounts` to track the number of accounts
created. Include:
- `static void incrementAccountCount()`: Increments the total account count when a
new account is created.
- `static int getTotalAccounts()`: Returns the current total number of accounts created.
4. Main Application:
Implement a `MainApp` class with a menu-driven program that performs the following
tasks:
- Create New Savings Account: Accepts account number and initial balance, then
creates a `SavingsAccount`. Increments the total account count.
- Create New Current Account: Accepts account number and initial balance, then
creates a `CurrentAccount`. Increments the total account count.
- Deposit Money: Allows users to deposit a specified amount into the account.
- Withdraw Money: Allows users to withdraw a specified amount (if sufficient
balance).
- Check Balance: Displays the current account balance.
- Calculate Interest: Calculates and applies interest to the account (only for
`SavingsAccount`).
- Display Total Accounts: Displays the total number of accounts created so far.
- Exit: Exits the program.

Menu Example:
1. Create New Savings Account
2. Create New Current Account
3. Deposit Money
4. Withdraw Money
5. Check Balance
6. Calculate Interest
7. Display Total Accounts
8. Exit

Sample Output:

1. Creating a Savings Account:


Enter account number: 12345
Enter initial balance: 1000
Savings Account Created
2. Depositing Money:
Enter deposit amount: 500
Deposited: 500

3. Withdrawing Money:
Enter withdrawal amount: 200
Withdrew: 200

4. Checking Balance:
Current Balance: 1300

5. Calculating Interest (Savings Account):


Interest added: 39.0

6. Display Total Accounts:


Total Accounts Created: 2

- Write the full implementation of all classes (`BankAccount`, `SavingsAccount`,


`CurrentAccount`, `Bank`, and `MainApp`).
- Ensure that your program properly demonstrates the use of static members, abstract
classes, and method overriding.
- Test the program by creating both `SavingsAccount` and `CurrentAccount` instances
and performing operations on them.

You might also like