Breaking News

Header Ads

Bank Management System program using Inheritance ,Packages ,Interfaces and Exception Handling in java



In this, we will learn how to create a small project like banking system using Java Language...

Flowchart for this project:-


Code:-

import BankDetails.deposit;
import BankDetails.withdraw;
import BankDetails.getprev_transaction;
import loan.Loan;
import java.util.*;

public class BankingApplication
{

public static void main(String args[])
{

Bank obj=new Bank();
deposit o= new deposit();

withdraw w=new withdraw();
getprev_transaction p=new getprev_transaction();
Loan l=new Loan();

int option='\0';
int option2='\0';
int option3='\0';
int balance=0;
Scanner sc=new Scanner(System.in);

System.out.println(" WELCOME TO TRUP BANK");

System.out.println("\n");
obj.accept();

do
{

System.out.println(" What would you like to do:");
System.out.println("1. Transaction");
System.out.println(" 2. Loan");
System.out.println(" 3. exit");
System.out.println("--------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------");
option=sc.nextInt();

switch(option)
{
case 1:

System.out.println(" What would you like to do?");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Previous Transactions");
System.out.println(" 4. exit");
System.out.println("-----------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------");
option2=sc.nextInt();

switch(option2)
{

case 1:

o.depositFun(obj.salary);

break;

case 2:
w.withdrawFun(obj.salary);
break;

case 3:

p.prevFun(obj.salary);

break;

case 4:
break;

default:
System.out.println("OOps! something went wrong!");
break;
}
break;


case 2:
System.out.println("\n");
System.out.println(" Which loan you want?");
System.out.println("1. Home loan");
System.out.println(" 2. Education loan");
System.out.println("3. Personal loan");

System.out.println(" 4. exit");
System.out.println(&"-----------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------");
option3=sc.nextInt();

switch(option3)
{
case 1:
l.loan1();
break;

case 2:
l.loan1();
break;

case 3:
l.loan1();
break;

case 4:
break;

default:
System.out.println("OOps! something went wrong!");
break;
}
break;


case 3:
break;

default:
System.out.println("OOps! something went wrong!");
break;
}
}
while(option!=3);
}
}

class Account
{
String name;
int account_no;
int salary;
}
class Bank extends Account
{
public void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your Name: ");
name=sc.nextLine();
System.out.println("Enter your account number: ");
account_no=sc.nextInt();
System.out.println("Enter your salary: ");
salary=sc.nextInt();
System.out.println("******************************************* ");
}
}


Package for deposit

package BankDetails;
import java.util.Scanner;
import java.lang.Exception;

public class deposit implements depo
{
public void depositFun(int salary)
{

Scanner sc=new Scanner(System.in);
int balance=0;
int dep;
int prev_transaction;
if(salary!=0)
{
System.out.println("Your current salary is : "+salary );
System.out.println("Amount you wanna deposit: ");
dep=sc.nextInt();
try
{
if(dep>0)
{
balance=salary + dep;

prev_transaction= balance;

System.out.println("After deposit your balance is "+balance);
System.out.println("******************************************* ");
}
else
{
throw new MyException("Deposit cannot be in negative");
//System.out.println("******************************************* ");

//System.out.println("******************************************* ");
}
}

catch(MyException e)
{
System.out.println(e.getMessage());
System.out.println("TRANSACTION FAILURE!!");
}

}
}
}

interface depo

{
public void depositFun(int salary);
}

class MyException extends Exception
{
MyException(String message)
{
super(message);
}
}


Package for withdraw


package BankDetails;
import java.util.Scanner;
import java.lang.Exception;
class MyException extends Exception
{
MyException(String message)
{
super(message);
}
}
public class withdraw implements withdraws
{

public double withdrawFun(int salary)
{
Scanner sc=new Scanner(System.in);
int withdrawn;

int balance=0;
int prev_transaction;
if(salary!=0)
{
System.out.println("Amount you wanna withdraw: ");
withdrawn=sc.nextInt();
try
{
if(withdrawn>0)
{
balance=salary - withdrawn;
prev_transaction= balance;

System.out.println("After withdraw your balance is "+balance);
System.out.println("****************************************** ");
}
else
{
throw new MyException("Deposit cannot be in negative");

}
}

catch(MyException e)
{
System.out.println(e.getMessage());
System.out.println("TRANSACTION FAILURE!!");
}

}
return balance;
}
}

interface withdraws
{
public double withdrawFun(int salary);
}

Package for prev_transaction
package BankDetails;

public class getprev_transaction implements prev

{
public void prevFun(int prev_transaction )
{

if(prev_transaction >0)
{
System.out.println("Amount deposited in the past: "+prev_transaction );
System.out.println("*******************************************");

}

else if(prev_transaction <0)
{
System.out.println("Amount Withdrawn in the past : "+Math.abs(prev_transaction));
System.out.println("******************************************* ");

}
else
{
System.out.println("NO TRANSACTION OCCURED!");
}
}
}

interface prev
{
public void prevFun(int prev_transaction );
}


Package for Loan

package loan;
import java.util.Scanner;

public class Loan implements Loan1
{
public void loan1()
{
Scanner sc=new Scanner(System.in);
int amount;
int time;

double t2=0.0;

double rate=0.0;
double total=0.0;
double t=0.0;
double interest=0.0;

System.out.println("Enter the amount");
amount=sc.nextInt();
System.out.println("Enter the time period");
time=sc.nextInt();

t=time*12;

if(amount>100000 && amount<500000)
{
rate=5.2;
}

else if(amount>500000 && amount<1000000)
{
rate=7;
}

else if(amount>1000000 && amount<20000000)
{
rate= 9;
}

else

{
rate=11.4;
}

interest=(amount*rate*t)/100;
total=interest+amount;
t2=amount/t;

System.out.println(amount+" at an interest of "+rate+ "and for a term of "+time+" years, the
monthly EMI comes to Rs. "+t2);

System.out.println("******************************************* ");

}
}

interface Loan1
{
public void loan1();
}


Output:-






Post a Comment

0 Comments