0% found this document useful (0 votes)
37 views

Banking System Java Project Report

Uploaded by

Shreyash Nigade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Banking System Java Project Report

Uploaded by

Shreyash Nigade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Banking System Java Project Report

1. Introduction
The Banking System Java Project is a simple application designed to simulate the core
functions of a banking system, allowing users to create accounts, log in, check balance,
deposit, and withdraw funds. This project uses Swing for the graphical user interface
(GUI) and file handling for data persistence. It provides a basic interface for managing
bank accounts, with functionalities such as account creation, user login, transaction
history, and balance tracking.

2. Technology Used
The project is developed using Java programming language and utilizes the following
technologies:
1. Java Swing for GUI components.
2. File I/O operations for data persistence (serialization and deserialization).
3. Collections (HashMap, ArrayList) for storing and managing user data and transactions.
4. Java Event Handling for user interactions like buttons, text fields, and action listeners.

3. System Requirements
To run this project, the following system requirements are necessary:
1. Java Development Kit (JDK) version 8 or higher.
2. Integrated Development Environment (IDE) such as Eclipse or IntelliJ IDEA.
3. Basic understanding of Java programming concepts like classes, methods, and GUI
development.

4. System Functionality
The system is designed to simulate a basic banking system with the following core
functionalities:
1. Account Creation: New users can create accounts with a unique username and
password.
2. Login: Registered users can log in by entering their credentials (username and
password).
3. Deposit: Users can deposit money into their account, and the balance is updated
accordingly.
4. Withdraw: Users can withdraw money from their account, provided they have
sufficient balance.
5. Check Balance: Users can check the current balance of their account at any time.
6. Transaction History: The system tracks all transactions, including deposits and
withdrawals, and displays them in a table.

5.Code
import javax.swing.*;

import java.awt.*;

import java.awt.event.*;
import javax.swing.table.DefaultTableModel;

import java.io.*;

import java.util.*;

public class BankingSystemSwing {

static Map<String, BankAccount> users = new HashMap<>();

static String currentUsername = "";


static DefaultTableModel tableModel = new DefaultTableModel(new Object[]{"Date",
"Type", "Amount", "Balance"}, 0);

public static void main(String[] args) {

// Load users from a file

loadUsers();

// Initial welcome screen

JFrame frame = new JFrame("Banking System");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 500);

frame.setLocationRelativeTo(null);
JPanel panel = new JPanel();

panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

JLabel lblWelcome = new JLabel("Welcome to the Banking System");

lblWelcome.setAlignmentX(Component.CENTER_ALIGNMENT);

JButton btnLogin = new JButton("Login");

JButton btnCreateAccount = new JButton("Create Account");

panel.add(Box.createRigidArea(new Dimension(0, 50)));


panel.add(lblWelcome);

panel.add(Box.createRigidArea(new Dimension(0, 30)));

JPanel buttonPanel = new JPanel(new FlowLayout());

buttonPanel.add(btnLogin);

buttonPanel.add(btnCreateAccount);

panel.add(buttonPanel);

frame.add(panel);
frame.setVisible(true);

// Create account button action listener

btnCreateAccount.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {


JFrame createAccountFrame = new JFrame("Create Account");

createAccountFrame.setSize(400, 300);
createAccountFrame.setLocationRelativeTo(null);

JPanel createAccountPanel = new JPanel(new GridLayout(3, 2));

JTextField tfUsername = new JTextField();

JPasswordField pfPassword = new JPasswordField();

createAccountPanel.add(new JLabel("Username:"));
createAccountPanel.add(tfUsername);

createAccountPanel.add(new JLabel("Password:"));

createAccountPanel.add(pfPassword);

JButton btnCreate = new JButton("Create");

createAccountPanel.add(btnCreate);

createAccountFrame.add(createAccountPanel);

createAccountFrame.setVisible(true);

// Create button listener

btnCreate.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {


String username = tfUsername.getText();

String password = new String(pfPassword.getPassword());


if (!users.containsKey(username)) {
// Create a new bank account for the user
BankAccount newAccount = new BankAccount(username, password,
0.0);
users.put(username, newAccount);

saveUsers(); // Save user data to file


JOptionPane.showMessageDialog(createAccountFrame, "Account
Created Successfully!");

createAccountFrame.dispose(); // Close the create account frame

} else {
JOptionPane.showMessageDialog(createAccountFrame, "Username
already exists!");

}
}

});

}
});

// Login button action listener

btnLogin.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {

JFrame loginFrame = new JFrame("Login");

loginFrame.setSize(400, 250);
loginFrame.setLocationRelativeTo(null);

JPanel loginPanel = new JPanel(new GridLayout(3, 2));


JTextField tfUsername = new JTextField();

JPasswordField pfPassword = new JPasswordField();

loginPanel.add(new JLabel("Username:"));

loginPanel.add(tfUsername);

loginPanel.add(new JLabel("Password:"));

loginPanel.add(pfPassword);

JButton btnSubmit = new JButton("Login");


loginPanel.add(btnSubmit);

loginFrame.add(loginPanel);

loginFrame.setVisible(true);

// Login button listener

btnSubmit.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {

String username = tfUsername.getText();

String password = new String(pfPassword.getPassword());

if (users.containsKey(username)) {

BankAccount account = users.get(username);

if (account.getPassword().equals(password)) {
currentUsername = username;

loginFrame.dispose(); // Close login frame


showMainBankingInterface();

} else {
JOptionPane.showMessageDialog(loginFrame, "Incorrect
password.");

}
} else {
JOptionPane.showMessageDialog(loginFrame, "Username does not
exist.");

});
}

});

private static void showMainBankingInterface() {

JFrame mainFrame = new JFrame("Banking System - " + currentUsername);

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainFrame.setSize(600, 600);
mainFrame.setLocationRelativeTo(null);

JPanel panel = new JPanel();


panel.setLayout(new GridBagLayout());

GridBagConstraints gbc = new GridBagConstraints();

gbc.insets = new Insets(10, 10, 10, 10);

BankAccount currentAccount = users.get(currentUsername);


JLabel lblAccountName = new JLabel("Account Name: " + currentUsername);

JLabel lblBalance = new JLabel("Balance: ");


JLabel lblBalanceValue = new JLabel("$" + currentAccount.getBalance());

JLabel lblDeposit = new JLabel("Deposit Amount:");

JTextField tfDeposit = new JTextField(15);

JLabel lblWithdraw = new JLabel("Withdraw Amount:");

JTextField tfWithdraw = new JTextField(15);

JButton btnDeposit = new JButton("Deposit");

JButton btnWithdraw = new JButton("Withdraw");

JButton btnCheckBalance = new JButton("Check Balance");

JButton btnLogout = new JButton("Log Out");

// JTable for displaying transaction history

JTable transactionTable = new JTable(tableModel);


JScrollPane scrollPane = new JScrollPane(transactionTable);

scrollPane.setPreferredSize(new Dimension(550, 150));

// Add components to the panel using GridBagLayout


gbc.gridx = 0;

gbc.gridy = 0;

panel.add(lblAccountName, gbc);

gbc.gridx = 0;

gbc.gridy = 1;
panel.add(lblBalance, gbc);

gbc.gridx = 1;

panel.add(lblBalanceValue, gbc);

gbc.gridx = 0;
gbc.gridy = 2;

panel.add(lblDeposit, gbc);

gbc.gridx = 1;
panel.add(tfDeposit, gbc);

gbc.gridx = 0;

gbc.gridy = 3;
panel.add(lblWithdraw, gbc);

gbc.gridx = 1;
panel.add(tfWithdraw, gbc);

gbc.gridx = 0;

gbc.gridy = 4;
panel.add(btnDeposit, gbc);

gbc.gridx = 1;

panel.add(btnWithdraw, gbc);

gbc.gridx = 0;
gbc.gridy = 5;

panel.add(btnCheckBalance, gbc);

gbc.gridx = 1;

panel.add(btnLogout, gbc);

gbc.gridx = 0;

gbc.gridy = 6;

gbc.gridwidth = 2;

panel.add(scrollPane, gbc);

// Add action listeners to the buttons

btnDeposit.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

try {

double amount = Double.parseDouble(tfDeposit.getText());


currentAccount.deposit(amount);

lblBalanceValue.setText("$" + currentAccount.getBalance());

updateTransactionHistory("Deposit", amount, currentAccount.getBalance());

saveUsers();
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(mainFrame, "Please enter a valid
amount.");

});
btnWithdraw.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {

try {

double amount = Double.parseDouble(tfWithdraw.getText());


if (currentAccount.getBalance() >= amount) {

currentAccount.withdraw(amount);

lblBalanceValue.setText("$" + currentAccount.getBalance());
updateTransactionHistory("Withdraw", amount,
currentAccount.getBalance());

saveUsers();
} else {

JOptionPane.showMessageDialog(mainFrame, "Insufficient balance.");

} catch (NumberFormatException ex) {


JOptionPane.showMessageDialog(mainFrame, "Please enter a valid
amount.");

}
}

});

btnCheckBalance.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {


JOptionPane.showMessageDialog(mainFrame, "Your current balance is $" +
currentAccount.getBalance());

}
});

btnLogout.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

mainFrame.dispose();
currentUsername = "";

JOptionPane.showMessageDialog(mainFrame, "Logged out successfully.");

main(null); // Return to the login screen

}
});

mainFrame.add(panel);

mainFrame.setVisible(true);
}

// Update transaction history in the table


private static void updateTransactionHistory(String type, double amount, double
balance) {

tableModel.addRow(new Object[]{new Date(), type, amount, balance});


}

// Save users to a file


private static void saveUsers() {

try {
ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream("users.dat"));

out.writeObject(users);
out.close();

} catch (IOException ex) {


ex.printStackTrace();

// Load users from a file

private static void loadUsers() {

try {

File file = new File("users.dat");


if (file.exists()) {

ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));

users = (Map<String, BankAccount>) in.readObject();

in.close();
}

} catch (IOException | ClassNotFoundException ex) {

ex.printStackTrace();
}

// BankAccount class to store user information

class BankAccount implements Serializable {

private String username;

private String password;


private double balance;

private List<String> transactionHistory = new ArrayList<>();


public BankAccount(String username, String password, double balance) {
this.username = username;

this.password = password;

this.balance = balance;

public String getUsername() {

return username;

public String getPassword() {

return password;

public double getBalance() {

return balance;
}

public void deposit(double amount) {

this.balance += amount;
transactionHistory.add("Deposit: $" + amount);

public void withdraw(double amount) {


this.balance -= amount;

transactionHistory.add("Withdraw: $" + amount);


}

public List<String> getTransactionHistory() {

return transactionHistory;

6. System Flowchart
6. Code Explanation
The core classes and methods of the project are explained as follows:
1. BankAccount Class: Represents a bank account. It includes methods for depositing,
withdrawing, and checking balance.
2. BankingSystemSwing Class: This is the main class that handles the user interface
(GUI) and business logic, including account creation, login, transaction handling, and
display of transaction history.
3. Event Handlers: ActionListeners are used for handling events like button clicks for
login, deposit, and withdrawal operations.
4. Data Persistence: The user data is serialized and saved in a file (users.dat), ensuring
that data persists even after the application is closed.
7. Conclusion
This Banking System project demonstrates a basic implementation of core banking
functionalities in Java. It serves as a valuable learning tool for those familiarizing
themselves with Java programming and Swing for GUI development. The project is
designed to simulate real-world banking operations while offering a practical example of
data persistence using file I/O operations.
Although the system is basic, it provides a solid foundation for future expansions, and
with enhancements such as better security, advanced features, and a mobile version, the
project has the potential to evolve into a fully functional banking application. By
integrating more advanced technologies and testing methodologies, the system could be
made ready for real-world deployment.
Reference
• Java: The Complete Reference" by Herbert Schildt
• Oracle Java Documentation
• Banking System Design and Implementation(Research Paper)
• W3Schools - Java File Handling

You might also like