/****************************************************************************************Roshni ChengappaComp 110-Program 610/17/2006Honor Pledge-I have neither given nor received unauthorized aid on this program.Purpose: To create a bank account program where the user can enter deposit,withdraw and see their current balance using a GUIinput-to get the amount for withdraw and deposit from the user after the user puts in their account numberoutput-the user can check how much money is left in their bank account*****************************************************************************************/import java.awt.event.*;import java.awt.*; import javax.swing.*;import java.io.*;import java.util.*; class program6_frame extends JFrame { private JLabel depositL, withdrawL, checkBalanceL; private JTextField depositTF, withdrawTF, checkBalanceTF; private JButton calculateB, exitB, checkBalanceB; private Container content; private ExitButtonHandler ebHandler; private CalculateButtonHandler cbHandler; private CheckBalanceHandler cbbHandler; private BankAccount acc; public program6_frame() { final int WIDTH = 500; final int HEIGHT = 500; int checkBalance; acc = new BankAccount(0,1); //asks user how much money they want to deposit and withdraw depositL = new JLabel("Enter the amount you want to deposit: ", SwingConstants.RIGHT); withdrawL = new JLabel("Enter the amount you want to withdraw: ", SwingConstants.RIGHT); //user is required to enter amount into the text field depositTF = new JTextField(10); withdrawTF = new JTextField(10); checkBalanceTF = new JTextField(10); //after entering the amounts, the user can press the calculate button to see the new balance after depositing or withdrawing calculateB = new JButton("Calculate"); cbHandler = new CalculateButtonHandler(); calculateB.addActionListener(cbHandler); //user can press the button "exit" when finished with transaction exitB = new JButton("Exit"); ebHandler = new ExitButtonHandler(); exitB.addActionListener(ebHandler); //user can find out how much the current balance is checkBalanceB = new JButton("Check balance"); cbbHandler = new CheckBalanceHandler(); checkBalanceB.addActionListener(cbbHandler); content = getContentPane(); //creates frame setTitle("Roshni's Bank: Welcome to your account"); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(EXIT_ON_CLOSE); content.setLayout(new GridLayout (6, 4)); content.add(depositL); content.add(depositTF); content.add(withdrawL); content.add(withdrawTF); setVisible(true); deposit depositListener = new deposit(); withdraw withdrawListener = new withdraw(); CheckBalanceHandler CheckBalanceListener = new CheckBalanceHandler(); /** @param creates the button for deposit */ JButton depositButton = new JButton("deposit"); depositButton.addActionListener(depositListener); content.add(depositButton); /** @param creates the button for withdraw */ JButton withdrawButton = new JButton("withdraw"); withdrawButton.addActionListener(withdrawListener); content.add(withdrawButton); /** @param creates the button for check balance */ JButton CheckBalanceButton = new JButton("Check balance"); CheckBalanceButton.addActionListener(CheckBalanceListener); content.add(CheckBalanceButton); content.setVisible(true); pack(); }class BankAccount{ private int acnum; public double currentBalance; //asks user to enter their account number which will be stored public BankAccount(double amount, int acnumToSave) { currentBalance = amount; acnum = acnumToSave; } /**checkBalance returns the current balance. @return double the current account balance in dollars */ public double checkBalance() { return currentBalance; } /**deposit returns the the amount of money user wants to deposit @return double the amount of money to deposit in dollars */ public double deposit(double deposit) { //adds the amount deposited to current balance to give new total currentBalance = currentBalance + deposit; return deposit; } /**withdraw returns the the amount of money user wants to withdraw @return double the amount of money to withdraw in dollars */ public double withdraw (double withdraw) { if ((currentBalance - withdraw) < 0) { System.out.println("Your have overdrafted, your balance is now negative. You will be charged $30 for overdrawing"); withdraw = withdraw + 30; currentBalance = currentBalance - withdraw; } if (currentBalance - withdraw > 0) { System.out.println("You have withdrawn" + withdraw + "dollars"); //subtracts the amount withdrawn from current balance to give new total currentBalance = currentBalance - withdraw; } return withdraw; }} private class CalculateButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { double amount, deposit, withdraw; int acnum; } } private class CheckBalanceHandler implements ActionListener { public void actionPerformed(ActionEvent e) { double balance; balance = acc.checkBalance(); } } private class ExitButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } public class deposit implements ActionListener { public void actionPerformed(ActionEvent e) { double deposit; deposit = Double.parseDouble(depositTF.getText()); acc.deposit(deposit); } } public class withdraw implements ActionListener { public void actionPerformed(ActionEvent e) { { double withdraw; withdraw = Double.parseDouble(withdrawTF.getText()); acc.withdraw(withdraw); } } } } public class program6_2 { public static void main(String[] args) { JFrame frame = new program6_frame(); frame.show(); } }