Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

1

Bank Application

Report

Name: Bikash Bhandari

Bsc.IT, CGIM, Limkokwing University

Instructor: Kiran Rana Magar

Due Date: Nov 12, 2022

JAVA | Bank System


2

Acknowledgements

I would like to acknowledge our subject instructor Mr. Kiran Rana Magar
for giving me the chance to create Bank application to manage customers
details of Bank. From this project I got chance to develop my skill on
database, java programming, research and decision making.

JAVA | Bank System


3

Contents

Acknowledgement
…………………………………………………………………………………………………………….2
Introduction
…………….....……………………………………………………………………………………………4
Objective
…………………………………………………………………………………………………………….4
What I did
…………..………………………………………………………………………………..……………….4
ER Diagram
…………..………………………………………………………………………………..……………….5
Screenshoot of
Database...................…….…………………………………………………………………………….......6
Screenshoot of code…………………………………………………………………………………...7-22
Screenshoot of Output………………………………………………………………………………..23-32

JAVA | Bank System


4

1. Introduction

Bank application project is a model application. Specific staff of bank can use this application to
perform simple banking operations using this application through computing devices. The system
helps Employee of bank to create accounts of customer, keep withdraw detail, and check balances
as well as search customers by account number of saving as well as salary account and display
detailed information about all customers.

2. Objectives

 To create new account with number auto generating features.


 To manage the existing account.
 To keep detail of deposit and withdraw in database.
 To fulfill the tasks that any customer desire.
 To save customer and employee time by using system in place of manual system.

3. What I did

I conducted some requirement analysis after reviewing the provided scenario, and I discovered
that we needed to construct a banking application with capabilities like account creation, account
editing, money deposits, money withdrawals, and account balance checking. In order to manage
customer data, we need to interconnect the application with the database. I started the process by
creating an ER diagram first, then I created the database and wrote a java programmed in Visual
Studio Code based on it.

JAVA | Bank System


5

4. ER-Diagram

JAVA | Bank System


6

5. Database

JAVA | Bank System


7

6. Code and Output

 Database Connection
 package databaseconnection;

 import java.sql.*;

 public class DbConnection {

 Connection con;
 Statement st;
 ResultSet rows;
 int val;

 public DbConnection() {
 try {
 String username = "root";
 String password = "database2";
 Class.forName("com.mysql.cj.jdbc.Driver");

 con = DriverManager.getConnection(
 "jdbc:mysql://localhost:3306/bank", username,
password);

 if (con != null) {
 System.out.println("connected to bank database");
 } else {
 System.out.println("error connecting database");
 }

 st = con.createStatement();
 }

 catch (Exception e) {
 e.printStackTrace();
 }
 }

 public int manipulate(String query) {
 try {
 val = st.executeUpdate(query);
 // con.close();
 } catch (SQLException throwables) {

JAVA | Bank System


8

 throwables.printStackTrace();
 }
 return val;
 }

 public ResultSet retrive(String query) {
 try {
 rows = st.executeQuery(query);
 // con.close();
 } catch (SQLException throwables) {
 throwables.printStackTrace();
 }
 return rows;
 }

 // public static void main(String[] args) {
 // new DbConnection();
 // }
 }

Output:

JAVA | Bank System


9

 Customer Controller

 package view;

 import java.sql.ResultSet;

 import databaseconnection.DbConnection;
 import model.Account;
 import model.Customer;

 public class CustomerController {

 DbConnection db;

 public int createAccount(Customer customer) {
 String query;
 // Accountno,fName,lNname,Address,DOB,accType

 query = "insert into customer
(Accountno,fName,lName,Address,DOB,accType,balance) values('" +
 customer.getAccountno() + "','" +
 customer.getFName() + "','" +
 customer.getLName() + "','" +
 customer.getAddress() + "','" +
 customer.getDOB() + "','" +
 customer.getAccType() + "','" +
 customer.getBalance() + "');";

 // query = "insert into
Customer(Accountno,fName,lNname,Address,DOB,accType)
 // values (234,'Bijay','Bhandari','Kalimati','2001-8-23',2);";

 db = new DbConnection();
 return db.manipulate(query);

 }
 // Accountno,fName,lName,Address,DOB,accType,balance

 public int Updatedetail(Customer customer, int Accountno) {
 String query = "Update customer " +
 "set fName='" + customer.getFName() + "'," +
 "lName='" + customer.getLName() + "'," +
 "Address='" + customer.getAddress() + "'," +
 "DOB='" + customer.getDOB() + "'," +
 "accType='" + customer.getAccType() + "'" +

JAVA | Bank System


10

 "Where Accountno ='" + Accountno + "';";



 db = new DbConnection();
 return db.manipulate(query);

 }

 public Customer AccountCheck(int Accountno) {
 String query;
 query = "select * from Customer where Accountno = '" + Accountno +
"';";
 db = new DbConnection();

 ResultSet rs = db.retrive(query);
 Customer customer = null;
 try {
 while (rs.next()) {
 customer = new Customer();
 customer.setFName(rs.getString("fName"));
 customer.setLName(rs.getString("lName"));
 customer.setAddress(rs.getString("Address"));
 customer.setDOB(rs.getString("DOB"));
 customer.setAccType(rs.getInt("accType"));
 }
 } catch (Exception ex) {
 System.out.println("Error" + ex);
 }
 return customer;
 }

 public int deposit(int Amount, int Accountno) {
 // int balance=

 String query = "select * from Customer where Accountno = '" +
Accountno + "';";
 db = new DbConnection();

 int balance = 0, nbalance = 0;
 ResultSet rs = db.retrive(query);
 try {
 while (rs.next()) {
 balance = rs.getInt("balance");
 nbalance = balance + Amount;
 }
 } catch (Exception ex) {

JAVA | Bank System


11

 System.out.println("Error" + ex);
 }
 String query1 = "Update customer set balance='" + nbalance +
"'Where Accountno ='" + Accountno + "';";

 db = new DbConnection();
 return db.manipulate(query1);

 }

 public int Withdraw(int Amount, int Accountno) {
 // int balance=

 String query = "select * from Customer where Accountno = '" +
Accountno + "';";
 db = new DbConnection();

 int balance = 0, nbalance = 0;
 ResultSet rs = db.retrive(query);
 try {
 while (rs.next()) {
 balance = rs.getInt("balance");

 if (balance < Amount) {
 return 3;
 }

 nbalance = balance - Amount;
 }
 } catch (Exception ex) {
 System.out.println("Error" + ex);
 }
 String query1 = "Update customer set balance='" + nbalance +
"'Where Accountno ='" + Accountno + "';";

 db = new DbConnection();
 return db.manipulate(query1);

 }

 public int Entry(Account account) {
 return 0;
 }
 }

JAVA | Bank System


12

 Customer Model

package model;

//import javax.print.DocFlavor.STRING;
public class Customer {

private int CustId;


private int Accountno;
private String fName;
private String lName;
private String Address;
private String DOB;
private int accType;
private int balance;

// for select,update
Customer(int custId, int Accountno, String fName, String lName, String
address, String DOB, int accType,
int balance) {
this.CustId = custId;
this.fName = fName;
this.lName = lName;
this.Address = address;
this.DOB = DOB;
this.accType = accType;
this.balance = balance;
}

// for insert
public Customer(int Accountno, String fName, String lName, String address,
String DOB, int accType, int balance) {
this.Accountno = Accountno;
this.fName = fName;
this.lName = lName;
this.Address = address;
this.DOB = DOB;
this.accType = accType;
this.balance = balance;

// update

JAVA | Bank System


13

public Customer(String fName, String lName, String address, String DOB, int
accType) {
this.fName = fName;
this.lName = lName;
this.Address = address;
this.DOB = DOB;
this.accType = accType;

public Customer() {
}

/**
* @return int return the CustId
*/
public int getCustId() {
return CustId;
}

/**
* @param CustId the CustId to set
*/
public void setCustId(int CustId) {
this.CustId = CustId;
}

/**
* @return int return the Accountno
*/
public int getAccountno() {
return Accountno;
}

/**
* @param Accountno the Accountno to set
*/
public void setAccountno(int Accountno) {
this.Accountno = Accountno;
}

/**
* @return String return the fName
*/
public String getFName() {

JAVA | Bank System


14

return fName;
}

/**
* @param fName the fName to set
*/
public void setFName(String fName) {
this.fName = fName;
}

/**
* @return String return the lName
*/
public String getLName() {
return lName;
}

/**
* @param lName the lName to set
*/
public void setLName(String lName) {
this.lName = lName;
}

/**
* @return String return the Address
*/
public String getAddress() {
return Address;
}

/**
* @param Address the Address to set
*/
public void setAddress(String Address) {
this.Address = Address;
}

/**
* @return String return the DOB
*/
public String getDOB() {
return DOB;
}

JAVA | Bank System


15

/**
* @param DOB the DOB to set
*/
public void setDOB(String DOB) {
this.DOB = DOB;
}

/**
* @return int return the accType
*/
public int getAccType() {
return accType;
}

/**
* @param accType the accType to set
*/
public void setAccType(int accType) {
this.accType = accType;
}

/**
* @return int return the balance
*/
public int getBalance() {
return balance;
}

/**
* @param balance the balance to set
*/
public void setBalance(int balance) {
this.balance = balance;
}

JAVA | Bank System


16

 Customer View

package view;

import java.sql.ResultSet;
import java.util.Scanner;

import databaseconnection.DbConnection;
import model.Customer;

public class CustomerView {

int CustId;
int Accountno;
String fName;
String lName;
String Address;
String DOB;
int accType;
int balance;
int Amount;

public static void main(String[] args) {


char ch;
try (Scanner sc = new Scanner(System.in)) {
do {
System.out.println("");
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=");
System.out.println("*#*#*#*#*#*#* WELCOME TO SAKIB BANK
*#*#*#*#*#*#*");
System.out.println(" ");
System.out.println("# 1.create
Account #");
System.out.println("# 2.Edit
Account #");
System.out.println("# 3.Deposit
Money #");
System.out.println("# 4.Withdraw
Money #");
System.out.println("# 5.Check
Aalance #");
System.out.println("# 6.Exit
#");

JAVA | Bank System


17

System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=");
System.out.println(" ");
System.out.println("WHAT DO YOU WANT TO DO? CHOOSE ONE OPTION
PLEASE:");
int choice = sc.nextInt();

switch (choice) {
case 1:
System.out.println(" ");
System.out.println("*#*#*#*#*#*#* Create Account
*#*#*#*#*#*#*");

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

// Accountno,fName,lNname,Address,DOB,accType
System.out.println("Enter your Account Number:(EXACTLY 5
NUMBER):");
int Accountno = sc.nextInt();

System.out.println("Enter your First Name:");


String fName = sc.next();

System.out.println("Enter your Last Name:");


String lName = sc.next();

System.out.println("Enter your Address:");


String Address = sc.next();

System.out.println("Enter your DOB:");


String DOB = sc.next();

System.out.println("Enter your Account Type Number(note:


1= Saving and 2 = Salary):");
int accType = sc.nextInt();

System.out.println("Enter Opening Balance:");


int balance = sc.nextInt();

Customer customer = new Customer(Accountno, fName, lName,


Address, DOB, accType, balance);
CustomerController controller = new CustomerController();
int insert = controller.createAccount(customer);

JAVA | Bank System


18

if (insert > 0) {
System.out.println("Customer added successfully");
} else {
System.out.println("Error registering customer");
}
System.out.println(
"------------------------------------------------
----");

break;
case 2: {

System.out.println("*#*#*#*#*#*#* Edit Detail


*#*#*#*#*#*#*");

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

System.out.println("FOR verification please Enter your


Account Number:(EXACTLY 5 NUMBER):");
Accountno = sc.nextInt();

CustomerController controller2 = new


CustomerController();
Customer customer2 = controller2.AccountCheck(Accountno);

System.out.println("-_-_-_-_-_Enter Data For Update_-_-


_-_-_-");

if (customer2 != null) {

System.out.println("Enter your first name:");


fName = sc.next();

System.out.println("Enter your Last name:");


lName = sc.next();

System.out.println("Enter your Address:");


Address = sc.next();

System.out.println("Enter your DOB:");


DOB = sc.next();

JAVA | Bank System


19

System.out.println("Enter your acctype no(choose


1(Saving) or 2(Salary)):");
accType = sc.nextInt();

Customer cust = new Customer(fName, lName, Address,


DOB, accType);
CustomerController controller3 = new
CustomerController();
int update = controller3.Updatedetail(cust,
Accountno);

if (update > 0) {
System.out.println("Successful");
} else
System.out.println("not");

} else {
System.out.println("invalid account ");
}
System.out.println(
"------------------------------------------------
----");

break;

case 3: {

System.out.println("*#*#*#*#*#*#*Deposit
Money*#*#*#*#*#*#*");

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

System.out.println("FOR verification please Enter your


Account Number:(EXACTLY 5 NUMBER):");
Accountno = sc.nextInt();

CustomerController controller2 = new


CustomerController();
Customer customer2 = controller2.AccountCheck(Accountno);

if (customer2 != null) {

JAVA | Bank System


20

System.out.println("Enter deposit Ammount:");


int Amount = sc.nextInt();
CustomerController controller3 = new
CustomerController();
int update = controller3.deposit(Amount, Accountno);

if (update > 0) {
System.out.println("Successful");
} else
System.out.println("not");

}
System.out.println(
"------------------------------------------------
----");

break;

}
case 4: {

System.out.println("*#*#*#*#*#*#*WithDraw
Money*#*#*#*#*#*#*");
System.out.println(
"------------------------------------------------
----");
System.out.println("FOR verification please Enter your
Account Number:(EXACTLY 5 NUMBER):");
Accountno = sc.nextInt();

CustomerController controller2 = new


CustomerController();
Customer customer2 = controller2.AccountCheck(Accountno);

if (customer2 != null) {
System.out.println("Enter Withdraw Ammount");
int Amount = sc.nextInt();
CustomerController controller3 = new
CustomerController();
int update = controller3.Withdraw(Amount, Accountno);

if (update > 0) {
System.out.println("Successful");
} else
System.out.println("not");

JAVA | Bank System


21

}
System.out.println(
"------------------------------------------------
----");

break;

}
case 5: {

System.out.println("*#*#*#*#*#*#*Check
Balance*#*#*#*#*#*#*");

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

System.out.println("FOR verification please Enter your


Account Number:(EXACTLY 5 NUMBER):");
Accountno = sc.nextInt();

CustomerController controller2 = new


CustomerController();
Customer customer2 = controller2.AccountCheck(Accountno);

if (customer2 != null) {
int cbalance = 0;
DbConnection db = new DbConnection();
ResultSet rs;

String query = "select * from Customer where


Accountno = '" + Accountno + "';";
rs = db.retrive(query);

try {
while (rs.next()) {
cbalance = rs.getInt("balance");
}
} catch (Exception e) {
System.out.println(e);
}

System.out.println("Your balance is: " + cbalance);

JAVA | Bank System


22

}
System.out.println(
"------------------------------------------------
----");

break;
}

case 6: {
System.exit(1);
}

System.out.println("*-------Thank You-------*");
System.out.println("Do you want to continue?");
ch = sc.next().charAt(0);
} while (ch == 'y' || ch == 'Y');
}

JAVA | Bank System


23

Overall Output

Create Account

Account number 99999 inserted into Database.

JAVA | Bank System


24

Edit Account

Account number 99999 has been edited in Database.

JAVA | Bank System


25

Deposit Money

Rs. 400 has been deposit into Account number.

JAVA | Bank System


26

Withdraw Money

Rs. 1700 has been deposit into Account number.

JAVA | Bank System


27

Check Balance

Exit

JAVA | Bank System


28

AccountType Model
package model;

public class Account {

private int S_N;


private static String AccountType;
private int AccountTypeno;
private int CustId;

// insert into AccountType(accType,accTypeno,custId) values('Saving',1,1000);

public Account(String accType, int accTypeno) {


// this.CustId = custId;
Account.AccountType = accType;
this.AccountTypeno = accTypeno;
}

public int getS_N() {


return S_N;
}

public void setS_N(int s_N) {


S_N = s_N;
}

public static String getAccountType() {


return AccountType;
}

public void setAccountType(String accountType) {


AccountType = accountType;
}

public int getAccountTypeno() {


return AccountTypeno;
}

public void setAccountTypeno(int accountTypeno) {


AccountTypeno = accountTypeno;
}

public int getCustId() {


return CustId;

JAVA | Bank System


29

}
public void setCustId(int custId) {
CustId = custId;
}

public static String accType() {


return null;
}

public static String getAccountno() {


return null;
}

AccountType Controller
package Controller;

import databaseconnection.DbConnection;
import model.Account;

public class AccountController {

DbConnection db;

public int Entry(Account account) {


String query;

// insert into AccountType(accType,accTypeno,custId)


values('Saving',1,1000);

query = "insert into AccountType(accType,accTypeno) values('" +


Account.getAccountType() + "','" +
Account.getAccountno() + "');";

// query = "insert into


Customer(Accountno,fName,lNname,Address,DOB,accType)
// values (234,'Bijay','Bhandari','Kalimati','2001-8-23',2);";

db = new DbConnection();
return db.manipulate(query);
}
}

JAVA | Bank System


30

Account Type View


package view;

import java.util.Scanner;

import Controller.AccountController;
import model.Account;

public class AccountView {


public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter your Account Type):");
String accType = sc.next();

System.out.println("Enter account type no:");


int accTypeno = sc.nextInt();

// insert into AccountType(accType,accTypeno,custId)


values('Saving',1,1000);

Account account = new Account(accType, accTypeno);


AccountController controller = new AccountController();
int insert = controller.Entry(account);
if (insert > 0) {
System.out.println("Customer added successfully");
} else {
System.out.println("Error registering customer");
}
}
}
}

JAVA | Bank System


31

Account Type database

Thank You

JAVA | Bank System

You might also like