Results 1 to 4 of 4
  1. #1
    buzzing is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default Make statements from the bank account program and implement charges

    Hi everyone,

    I have been trying to make a statement from the bank account programme. It works for withdraw and adding balance but i want to make a statement. Also i need to make two classes of bank account one of which the charge will be 1 per withdrawal and another one is 10 one off charge each month. Here inheritence need to be used. And at the end the GUI should generate the statements and the charges accordingly. I am nearly there. But could not get it right. Need help.

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class GuiAccTest extends Frame implements ActionListener
    {
            Label lab=new Label("                                                                                                                                                                 ");
            Label lab1=new Label("                                                                                                                                                                 ");
            TextField t[]=new TextField [4];
            Label l[]=new Label [4];
            Button but=new Button("Create Account");
            Button but1=new Button("Test Account");
            BankAccount b;
            GuiAccTest()
            {
                    addWindowListener(new NewWindowAdapter());
                    setLayout(new GridLayout(2,0));
                    Panel p=new Panel();
                    Panel p1=new Panel();
                    but.addActionListener(this);
                    but1.addActionListener(this);
                    p.setLayout(new GridLayout(5,2));
                    p1.add(lab1);
                    p1.add(lab);
                    l[0]=new Label("Account Number");
                    l[1]=new Label("Initial Balance");
                    l[2]=new Label("Deposit Amount");
                    l[3]=new Label("Withdraw Amount");
                    for(int i=0;i<4;i++)
                    {
                            t[i]=new TextField(10);
                            p.add(l[i]);
                            p.add(t[i]);
                    }
                    p.add(but);
                    p.add(but1);
                    but1.setVisible(false);
                    l[2].setVisible(false);
                    l[3].setVisible(false);
                    t[2].setVisible(false);
                    t[3].setVisible(false);
                    add(p);
                    add(p1);
            }
            String testAccount(int d_amt,int w_amt)
            {
                    String msg;
                    b.deposit(d_amt);
                    msg="Transaction Succesful";
                    try
                    {
                            b.withdraw(w_amt);
                    }catch(FundsInsufficientException fe)
                    {
                            fe=new FundsInsufficientException(b.amount,w_amt);
                            msg=String.valueOf(fe);
                    }
                    return msg;
            }
            public void actionPerformed(ActionEvent ae)
            {
                    String str=ae.getActionCommand();
                    if(str.equals("Create Account"))
                    {
                            b=new BankAccount(Integer.parseInt(t[0].getText()),Integer.parseInt(t[1].getText()));
                            but1.setVisible(true);
                            l[2].setVisible(true);
                            l[3].setVisible(true);
                            t[2].setVisible(true);
                            t[3].setVisible(true);
                            but.setVisible(false);
                            l[0].setVisible(false);
                            l[1].setVisible(false);
                            t[0].setVisible(false);
                            t[1].setVisible(false);
                            lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
                            return;
                    }
                    else
                    {
                            lab.setText(testAccount(Integer.parseInt(t[2].getText()),Integer.parseInt(t[3].getText())));
                            lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
                    }
            }
            public static void main(String arg[])
            {
                    GuiAccTest at=new GuiAccTest();
                    at.setTitle("Bank Account Tester");
                    at.setSize(600,200);
                    at.setVisible(true);
            }
    }
    class NewWindowAdapter extends WindowAdapter
    {
            public void windowClosing(WindowEvent we)
            {
                    System.exit(0);
            }
    }
    class BankAccount
    {
            int accnum;
            int amount;
            BankAccount(int num,int amt)
            {
                    accnum=num;
                    amount=amt;
            }
            public void deposit(int amt)
            {
                    amount=amount+amt;
            }
            public void withdraw(int amt) throws FundsInsufficientException
            {
                    if(amt>amount)
                            throw new FundsInsufficientException(amount,amt);
                    else
                            amount=amount-amt;
            }
    }
    class FundsInsufficientException extends Exception
    {
            int balance;
            int withdraw_amount;
            FundsInsufficientException(int bal,int w_amt)
            {
                    balance=bal;
                    withdraw_amount=w_amt;
            }
            public String toString()
            {
                    return "Your withdraw amount ("+withdraw_amount+") is less than the balance ("+balance+"). No withdrawal was recorded.";
            }
    }
    Last edited by buzzing; 10-31-2010 at 03:43 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    What you really means by a statement? Kind of a summary for all your transaction in the account class?

  3. #3
    buzzing is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    What you really means by a statement? Kind of a summary for all your transaction in the account class?
    That's right. I need to make a statement according to date. Any other question welcome.
    Last edited by buzzing; 10-31-2010 at 11:55 AM.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In your class you've pass amount and the account number I guess. So why you cannot simply print it from there, or pass it to relevant. I'm not sure where you stuck with, what you've tried so far?

Similar Threads

  1. java bank account problem
    By awil121 in forum New To Java
    Replies: 1
    Last Post: 10-13-2010, 10:47 PM
  2. Create a java class for a bank account!!?
    By singh345 in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 04:26 PM
  3. Bank Account
    By HPcompaq256 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 09:05 PM
  4. java program for updating bank details
    By java__beginner in forum New To Java
    Replies: 5
    Last Post: 03-12-2009, 03:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •