The java program developed here is to implement bank functionality. The user can create an account, check, deposit money, withdraw, and also search account. At first, we created an interface called the central bank to do a few operations mentioned above. Then we created three subclass UNB, FGB, and NBD these classes will take customer account details and then we created a class Bankdriver to invoke all the methods in the subclasses.
Design of the application using a class diagram
 
Implementation
Implementing classes/ interfaces namely Customer, Account, and CentralBank with required member variables and functions
Java
| publicinterfaceCentralBank{    longgetBalance();    voidwithdraw(longamount);    voiddeposit(longamount);    voidshowAccount();    booleansearch(String acc_no);} | 
Implementing the subclasses UNB, NBD, and FGB with required member variables and functions
UNB:
Java
| publicclassunb implementsCentralBank {      String name;    String accno;    String acc_type;    longbalance;     unb(String name, String accno, String acc_type, longbalance){        this.name = name; this.accno = accno; this.acc_type = acc_type;  this.balance = balance;    };    publiclonggetBalance(){        returnbalance;    }    publicvoidwithdraw(longamount){        if(balance >= amount) {             balance = balance - amount;             System.out.println("Balance after withdrawal: "+ balance);         } else{             System.out.println("Your balance is less than "+ amount + "\tTransaction failed...!!");         }     }    publicvoiddeposit(longamount){        balance = balance + amount;    }    publicvoidshowAccount(){        System.out.println("UNB Bank account");        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);     }    publicbooleansearch(String ac_no) {         if(accno.equals(ac_no)) {             showAccount();             return(true);         }         return(false);     }} | 
NBD:
Java
| importjava.util.*;publicclassnbd implementsCentralBank {          String name;        String accno;        String acc_type;        longbalance;                    nbd(String name, String accno, String acc_type, longbalance){            this.name = name; this.accno = accno; this.acc_type = acc_type;  this.balance = balance;        };            publiclonggetBalance(){            returnbalance;        }            publicvoidwithdraw(longamount){            if(balance >= amount) {                 balance = balance - amount;                 System.out.println("Balance after withdrawal: "+ balance);             } else{                 System.out.println("Your balance is less than "+ amount + "\tTransaction failed...!!");             }             }            publicvoiddeposit(longamount){            balance = balance + amount;            }            publicvoidshowAccount(){            System.out.println("NBD Bank account");            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);             }            publicbooleansearch(String ac_no) {             if(accno.equals(ac_no)) {                 showAccount();                 return(true);             }             return(false);         }        } | 
FGB:
Java
| importjava.util.*;publicclassfgb implementsCentralBank {      String name;    String accno;    String acc_type;    longbalance;    fgb(String name, String accno, String acc_type, longbalance){        this.name = name; this.accno = accno; this.acc_type = acc_type;  this.balance = balance;    };    publiclonggetBalance(){        returnbalance;    }    publicvoidwithdraw(longamount){        if(balance >= amount) {             balance = balance - amount;             System.out.println("Balance after withdrawal: "+ balance);         } else{             System.out.println("Your balance is less than "+ amount + "\tTransaction failed...!!");         }     }    publicvoiddeposit(longamount){        balance = balance + amount;    }    publicvoidshowAccount(){        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);     }    publicbooleansearch(String ac_no) {         if(accno.equals(ac_no)) {             showAccount();             return(true);         }         return(false);     }} | 
Implementing BankDriver class for creating the objects of subclasses and invoking their methods
Java
| importjava.util.*;publicclassBankDriver {    publicstaticCentralBank createAccount(ArrayList<CentralBank> C){        intchoice;        String name, accNo, acc_type;        longbalance;        booleanfound;        CentralBank cus1;        System.out.println("Enter ur Bank");        System.out.println("1.UNB 2.SGB 3. FGB");        Scanner sc = newScanner(System.in);        choice = sc.nextInt();        System.out.print("Enter Name: ");         name = sc.next();        System.out.print("Enter Account No: ");         accNo = sc.next();         System.out.print("Enter Account type: ");         acc_type = sc.next();          System.out.print("Enter Balance: ");         balance = sc.nextLong();        found = false;        for(inti = 0; i < C.size(); i++) {             found = C.get(i).search(accNo);             if(found) {                 System.out.println("Account with entered accNo already exists.");                break;             }         }         if(!found) {             switch(choice){                case1:if(balance < 1000)                        {                            System.out.println("Minimum balance is 1000. Please make sure your minimum balance is 1000");                        }                        else{                            cus1 = newunb(name, accNo, acc_type, balance);                            System.out.println("Account created");                            returncus1;                        }                        break;                case2:if(balance < 2000)                        {                            System.out.println("Minimum balance is 2000. Please make sure your minimum balance is 20000");                        }                        else{                            cus1 = newnbd(name, accNo, acc_type, balance);                            System.out.println("Account created in nbd");                            returncus1;                        }                        break;                    case3:if(balance < 3000)                        {                            System.out.println("Minimum balance is 3000. Please make sure your minimum balance is 5000");                        }                        else{                            cus1 = newfgb(name, accNo, acc_type, balance);                            System.out.println("Account created");                            returncus1;                        }                        break;                    default: System.out.println("Wrong Choice");                }        }                returnnull;    }    publicstaticvoidmain(String args[]){       Scanner sc = newScanner(System.in);        ArrayList<CentralBank> C = newArrayList<>();        System.out.println("No accounts found. Please Create one");        CentralBank cus1 = createAccount(C);        if(cus1 != null) {            C.add(cus1);        }                intch;         do{             System.out.println("\n #Banking System Application#");             System.out.println(" 1.Create an account \n2. Display all account details \n 3. Search by Account number\n 4. Deposit the amount \n 5. Withdraw the amount \n 6. Remove account\n 7.Exit ");             System.out.println("Enter your choice: ");             ch = sc.nextInt();                        switch(ch) {                 case1: CentralBank cus = createAccount(C);                        if(cus != null) {                            C.add(cus);                        }                        break;                case2:                     if(C.isEmpty()){                        System.out.println("No accounts found");                    }                    for(inti = 0; i < C.size(); i++) {                         C.get(i).showAccount();                     }                    break;                 case3:                     System.out.print("Enter account no. you want to search: ");                     String ac_no = sc.next();                     booleanfound = false;                     for(inti = 0; i < C.size(); i++) {                         found = C.get(i).search(ac_no);                         if(found) {                             break;                         }                     }                     if(!found) {                         System.out.println("Search failed! Account doesn't exist..!!");                     }                     break;                 case4:                     System.out.print("Enter Account no. : ");                     ac_no = sc.next();                     found = false;                     for(inti = 0; i < C.size(); i++) {                         found = C.get(i).search(ac_no);                         if(found) {                            System.out.println("Enter the amount to deposit");                            longamount = sc.nextLong();                            C.get(i).deposit(amount);                             break;                         }                     }                     if(!found) {                         System.out.println("Search failed! Account doesn't exist..!!");                     }                     break;                 case5:                     System.out.print("Enter Account No : ");                     ac_no = sc.next();                     found = false;                     for(inti = 0; i < C.size(); i++) {                         found = C.get(i).search(ac_no);                         if(found) {                             System.out.println("Enter the amount to withdraw");                            longamount = sc.nextLong();                            C.get(i).withdraw(amount);                             break;                         }                     }                     if(!found) {                         System.out.println("Search failed! Account doesn't exist.!");                     }                     break;                 case6:                     System.out.println("Enter your acc no: ");                    String temp = sc.next();                    found = false;                    for(inti = 0; i < C.size(); i++) {                         found = C.get(i).search(temp);                         if(found) {                             C.remove(i);                            System.out.println("Account deleted successfully");                            break;                         }                     }                     if(!found) {                         System.out.println("Search failed! Account doesn't exist.!");                     }                    break;                 case7: break;                default: System.out.println("Enter the correct Choice");                         break;            }         }         while(ch != 7);     } } | 
Output:
 
account created
 
choices
 
banking transaction-1
 
banking transaction-2


 
                                    







