Dr.
AMBEDKAR INSTITUTE OF TECHNOLOGY
Near Jnana Bharathi Campus, Bengaluru-560 056.
(An Autonomous Institution, Aided by Government of Karnataka)
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING
Advance Java Programming
Group Activity
Course Code: 21CSL504
No. of Credits: 3
Submitted by
CHETHANA S MURTHY(1DA21CS180)
KEERTHI B S(1DA21CS182)
VARSHITHA G A(1DA21CS159)
YASHASWINI S(1DA21CS170)
Submitted to
Mrs. Pushpaveni H P
Dept. of CSE
Dr. AIT
Department of Computer Science & Engineering 2023-24
BANKING MANAGEMENT SYSTEM
CODING:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BankingSystem extends JFrame implements ActionListener {
// Components
private JTextField accountField, amountField;
private JButton depositButton, withdrawButton, balanceButton;
private JTextArea displayArea;
private Bank bank;
public BankingSystem() {
// Set up frame
setTitle("Banking Management System");
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// Initialize bank
bank = new Bank();
// Create components
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridLayout(4, 2));
inputPanel.add(new JLabel("Account Number:"));
accountField = new JTextField();
inputPanel.add(accountField);
inputPanel.add(new JLabel("Amount:"));
amountField = new JTextField();
inputPanel.add(amountField);
depositButton = new JButton("Deposit");
depositButton.addActionListener(this);
inputPanel.add(depositButton);
withdrawButton = new JButton("Withdraw");
withdrawButton.addActionListener(this);
inputPanel.add(withdrawButton);
balanceButton = new JButton("Check Balance");
balanceButton.addActionListener(this);
inputPanel.add(balanceButton);
add(inputPanel, BorderLayout.NORTH);
displayArea = new JTextArea();
displayArea.setEditable(false);
add(new JScrollPane(displayArea), BorderLayout.CENTER);
setVisible(true);
}
// ActionListener implementation
public void actionPerformed(ActionEvent e) {
if (e.getSource() == depositButton) {
int accountNumber = Integer.parseInt(accountField.getText());
double amount = Double.parseDouble(amountField.getText());
bank.deposit(accountNumber, amount);
displayArea.append("Deposited $" + amount + " into account " + accountNumber +
"\n");
} else if (e.getSource() == withdrawButton) {
int accountNumber = Integer.parseInt(accountField.getText());
double amount = Double.parseDouble(amountField.getText());
if (bank.withdraw(accountNumber, amount))
displayArea.append("Withdrawn $" + amount + " from account " + accountNumber
+ "\n");
else
displayArea.append("Insufficient funds for withdrawal from account " +
accountNumber + "\n");
} else if (e.getSource() == balanceButton) {
int accountNumber = Integer.parseInt(accountField.getText());
double balance = bank.getBalance(accountNumber);
displayArea.append("Account " + accountNumber + " balance: $" + balance + "\n");
}
}
public static void main(String[] args) {
new BankingSystem();
}
}
class Bank {
private double[] accounts;
public Bank() {
// Initialize accounts with dummy data for demonstration purposes
accounts = new double[10];
for (int i = 0; i < accounts.length; i++) {
accounts[i] = 100; // Initial balance of $100 for each account
}
}
public void deposit(int accountNumber, double amount) {
accounts[accountNumber] += amount;
}
public boolean withdraw(int accountNumber, double amount) {
if (accounts[accountNumber] >= amount) {
accounts[accountNumber] -= amount;
return true;
}
return false;
}
public double getBalance(int accountNumber) {
return accounts[accountNumber];
}
}
OUTPUT: