Project 2
Write a JAVA program to implement bank functionality in the above scenario and demonstrate the OOPs concepts and explain how it is actually satisfying that concept.
Note:
- Create a console application for the banking management system.
- Create few classes namely Customer, Account, RBI (Base Class) and few derived classes (SBI, ICICI, PNB etc). Assume and implement required member variables and functions in each class.
- In every Bank there should be at least 2 types of account saving and current.
- Saving should give simple interest and Current should provide compound interest on deposited amount.
- In the current account the interest is compounded twice a year (on half yearly its compounded).
- For Every type of account at least 2 users will be there.
- On the running of the application it should ask which bank we want to access.
- Then what type of account you have.
- And then for which user account we want to access.
- Minimum amount for saving account is 2000/- and for current account is 5000/-
- And we can calculate the interest for any given time and total amount as well.
- Interest rates for saving will be 5% annually and for current it will be 8% annually.
- Before calculating interest it should ask the user for how many years you want to calculate it.
- Write code to calculate both types of interests as well for any of the users.
For total amount on Simple Interest:
A = P(1 + rt)
Where:
A = final Amount
P = initial Principal balance
r = annual interest rate
t = time (in years)
So, Total Interest = (A - P)
For total amount on Compound Interest:
π΄ = π(1 + π
π
)
ππ‘
A = final Amount
P = initial Principal balance
r = annual interest rate
t = time (in years)
n = number of times interest is compounded per year
|
Sample Input |
Sample Output |
|
Want to open an account? |
yes/No |
|
If yes, Insert name, type of account and date of birth, in which bank you want |
Account has been opened and account no is: 123 |
|
Want to print mini statement |
If yes, save it in .txt file somewhere |
|
Calculate interest |
If yes, calculate and print |
Hint:
Class Customer
{
//Personal Details ...
// Few functions ...
}
Class Account
{
// Account Detail ...
// Few functions ...
}
Class RBI
{
Customer c; //hasA relationship
Account a; //hasA relationship
..
Public double GetInterestRate() { }
Public double GetWithdrawalLimit() { }
}
Class SBI: public RBI
{
//Use RBI functionality or define own functionality.
}
Class ICICI: public RBI
{
//Use RBI functionality or define own functionality.
}
Code:
package BankingProject;
import java.util.Scanner;
class BankDetails {
private String accno;
private String name;
private String acc_type;
private long balance;
Scanner sc = new Scanner(System.in);
// method to open new account
public void openAccount() {
System.out.print("Enter Account No: ");
accno = sc.next();
System.out.print("Enter Account type: ");
acc_type = sc.next();
System.out.print("Enter Name: ");
name = sc.next();
System.out.print("Enter Balance: ");
balance = sc.nextLong();
}
// method to display account details
public void showAccount() {
System.out.println("Name of account holder: " + name);
System.out.println("Account no.: " + accno);
System.out.println("Account type: " + acc_type);
System.out.println("Balance: " + balance);
}
// method to deposit money
public void deposit() {
long amt;
System.out.println("Enter the amount you want to deposit: ");
amt = sc.nextLong();
balance = balance + amt;
}
// method to withdraw money
public void withdrawal() {
long amt;
System.out.println("Enter the amount you want to withdraw: ");
amt = sc.nextLong();
if (balance >= amt) {
balance = balance - amt;
System.out.println("Balance after withdrawal: " + balance);
} else {
System.out.println("Your balance is less than " + amt + "\tTransaction failed...!!");
}
}
// method to search an account number
public boolean search(String ac_no) {
if (accno.equals(ac_no)) {
showAccount();
return (true);
}
return (false);
}
}
------------
package BankingProject;
import java.util.Scanner;
public class BankingApp {
public static void main(String arg[]) {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
// create initial accounts
System.out.print("How many number of customers do you want to input? ");
int n = sc.nextInt();
BankDetails C[] = new BankDetails[n];
for (int i = 0; i < C.length; i++) {
C[i] = new BankDetails();
C[i].openAccount();
}
// loop runs until number 5 is not pressed to exit
int ch;
do {
System.out.println("\n ***Banking System Application***");
System.out.println(
"1. Display all account details \n 2. Search by Account number\n 3. Deposit the amount \n 4. Withdraw the amount \n 5.Exit ");
System.out.println("Enter your choice: ");
ch = sc.nextInt();
switch (ch) {
case 1:
for (int i = 0; i < C.length; i++) {
C[i].showAccount();
}
break;
case 2:
System.out.print("Enter account no. you want to search: ");
String ac_no = sc.next();
boolean found = false;
for (int i = 0; i < C.length; i++) {
found = C[i].search(ac_no);
if (found) {
break;
}
}
if (!found) {
System.out.println("Search failed! Account doesn't exist..!!");
}
break;
case 3:
System.out.print("Enter Account no. : ");
ac_no = sc.next();
found = false;
for (int i = 0; i < C.length; i++) {
found = C[i].search(ac_no);
if (found) {
C[i].deposit();
break;
}
}
if (!found) {
System.out.println("Search failed! Account doesn't exist..!!");
}
break;
case 4:
System.out.print("Enter Account No : ");
ac_no = sc.next();
found = false;
for (int i = 0; i < C.length; i++) {
found = C[i].search(ac_no);
if (found) {
C[i].withdrawal();
break;
}
}
if (!found) {
System.out.println("Search failed! Account doesn't exist..!!");
}
break;
case 5:
System.out.println("See you soon...");
break;
}
} while (ch != 5);
}
}
Output:
How many number of customers do you want to input? 1
Enter Account No: 123
Enter Account type: Saving
Enter Name: Hemant
Enter Balance: 2000
***Banking System Application***
1. Display all account details
2. Search by Account number
3. Deposit the amount
4. Withdraw the amount
5.Exit
Enter your choice:
3
Enter Account no. : 123
Name of account holder: Hemant
Account no.: 123
Account type: Saving
Balance: 2000
Enter the amount you want to deposit:
3000
***Banking System Application***
1. Display all account details
2. Search by Account number
3. Deposit the amount
4. Withdraw the amount
5.Exit
Enter your choice:
2
Enter account no. you want to search: 123
Name of account holder: Hemant
Account no.: 123
Account type: Saving
Balance: 5000
***Banking System Application***
1. Display all account details
2. Search by Account number
3. Deposit the amount
4. Withdraw the amount
5.Exit
Enter your choice:
5
See you soon...