hi people

I am building a atm machine but havent actually coding it as yet, just the gui interface part i have done so far because i am doing something else at the moment but in between i would do someting with it. so i have put in an if and else statement.

the atm should be work like this, when a person deposit any amount a pop box will tell u the money is deposit. it should also show u your current balance, bal enquiry, be able to get fast cash and able to widthdrawal right.

I have started with the widthdrawal part for. well i mean am just testing it out so i put in an if and else statement. the things is with the widthdrawal, i have put a limit to which a user can widthdraw, if the user goes beyond the required widthdrawal amount, a pop box will tell the user that it is an invalid transaction, meaning that the transaction entered exceeded the amount, but for some reason it only goes to the part where it tells the user to take the case when the wrong amount is entered when it should go to the else statement to tell the user that the wrong amount has been entered.

tell me what i have done wrong. I havent been programming for a while eh. here is the code that i used .

it is the same for the savings and the chequeing account.

any help will be appreciated.

private void jbtn_savingsWidrawalActionPerformed(java.awt.event.ActionEvent evt) {                                                     
      double moneyDeposit = 0;

      if(moneyDeposit > 2000)
      {
          JOptionPane.showMessageDialog(null, "Invalid transaction amount");
      }
      else 
      {
          JOptionPane.showMessageDialog(null, "Please take your cash");
      }

    }                                                    

    private void jbtn_chequeWidrawalActionPerformed(java.awt.event.ActionEvent evt) {                                                    
        double cash_widthdrawal=0;

      if(cash_widthdrawal == 2000)
      {
          JOptionPane.showMessageDialog(null, "Please take your cash");
      }
      else if(cash_widthdrawal > 2000)
      {
          JOptionPane.showMessageDialog(null, "Invalid transaction");
      }
    }                                                   
  2: double moneyDeposit = 0;
  3: 
  4:   if(moneyDeposit > 2000) // will always be false!!!

same problem lines 16-18

oka james but am getting two errors here
error no.1 when I remove the zero it is telling it need to initalizing and
error no.2 when i remove/grayout the variable, it is telling me to create a local variable and it cannot find symbol

what do i do and how do i fix this

Obviously moneyDeposit needs to be declared and have a value set before you can use it in an if test. (I find it deeply depressing that I need to explain that to someone who has been programmng for as long as you have.)

Only you know where that value should come from. Maybe it's a value that the user has typed into a text field somewhere?

This is an elementary programming error that suggests you are new to coding, and probably shouldnt be codinf an ATM application that must be secure and solid due to financiala regulation and high risk.

The problem is that you assign a value of 0 to a variable, then you check the value to see if it exceeds a limit. Since the variable is never actually assigned a value other than the initialized value, it will only ever be zero.

The next step is to assign that variable a value from the amount entry field kf the application to link the variable to a user assigned value.

There are other serious flaws in this code though. Because you hard coded the transaction limit to 2000, you will have to change the code to change the limit, and compiling & distributing code is a costly operation that can be easily avoided by getting the limit value from a configuration module that reads from a source . If reading from such values from a source, you also need to validate the values stored in that source or risk an injection vulnerability.

As you can see, if there is a lot wrong here, and I highly suggest more learning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.