mardi 8 décembre 2015

Because of If statement cannot log in

I want to login to the system. When create my customers with ID and account number, I am trying to input them and want that if ID and account are connected - the dialog will be open.

when I created customer ID, in my constructor I converted it to String:

Customer(int id, String pps, String name, String surname, String birthday, String password){

        this.id = nextId.incrementAndGet();
        Integer.toString(this.id);  

when I created account in another class, but for the customer, I did the same in my constructor (I converted account number to String):

public CustomerAccount(int accountNumber, double balance){

        Random n = new Random();
        this.accountNumber = 100000 + n.nextInt(900000);
        Integer.toString(this.accountNumber);

In my driver class, I have the button, and then, when I press the button, the dialogs should be open.

depositW.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                     JFrame frame = new JFrame(" ");
                     boolean found1 = false;
                     boolean found = false;


                     String a = JOptionPane.showInputDialog("Please enter the ID number: ");         
                     for(Customer aCustomer: customers){
                         System.out.println("ID: " + a + " = " + aCustomer.getId());
                         if(a.equals(aCustomer.getId())){
                             BankInterface.setCurrentCustomer(aCustomer);
                             found1 = true;
                         }else{
                  JOptionPane.showMessageDialog(frame, "There is no customer with this ID number", "Please try again", JOptionPane.WARNING_MESSAGE);
                       }

                if(found1){      
                     String b = JOptionPane.showInputDialog("Please enter the account number: ");   
                               for(CustomerAccount cu: BankInterface.getCurrentCustomer().getAccounts()){ 
                                   System.out.println("Account: " + a + " = " + cu.getAccountNumber());
                                   if(b.equals(cu.getAccountNumber())){

                                      BankInterface.setCurrentAccount(cu);
                                      found = true;
                                   }
                                }
                }

                if(found && found1){
                     new WithdrawDepositDialog(BankInterface.this, customers);
                }else{
                    JOptionPane.showMessageDialog(frame, "The username or password is not correct", "Please try again", JOptionPane.WARNING_MESSAGE);
                }
                  }
                    }
            }); 

When I test it, in my console window I have the following: So it does not find the id, when it is running.

ID: 1 = 1
ID: 1 = 2

I am now sure, what is the mistake. I guess something wring in my if statement. What will be the possible solution in this problem?

Aucun commentaire:

Enregistrer un commentaire