Results 1 to 7 of 7
  1. #1
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default How to create parallel arrays

    Is it sth like this

    int grades[][] = {} ?

  2. #2
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default

    I manage to figure out
    Java Code:
    String table[][] = {{"Vani", "Vicknes", "Kamala", "Vimal", "Bala"},
                           {"Vani1234", "Vick1234", "Kam1234", "Vimal90", "Bala62"}};

  3. #3
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default

    Now how am i to check against the array table with the login id and password i have keyed in to validate that its correct?

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class AccountLogin extends JFrame
    {
        String table[][] = {{"Vani", "Vicknes", "Kamala", "Vimal", "Bala"},
                           {"Vani1234", "Vick1234", "Kam1234", "Vimal90", "Bala62"}};
    //     String array2[] = {"Vani1234", "Vick1234", "Kam1234", "Vimal90", "Bala62"};
        private JLabel lblAccountId;
        private JTextField txtAccountId;
        private JLabel lblPassword;
        private JTextField txtPassword;
        private JButton btnLogin;
        private JLabel lblOutPut;
       // private char echochar = '*';
        
        public AccountLogin()
        {
           lblAccountId = new JLabel("Account ID");
           txtAccountId = new JTextField(15);
           lblPassword = new JLabel("Password");
           txtPassword = new JTextField(10);
           //txtPassword.setEchoChar('*');
           btnLogin = new JButton("Login");
           btnLogin.addActionListener(new MyListener());
           lblOutPut = new JLabel();
           
           JPanel panel = (JPanel)getContentPane();
           panel.setLayout(new FlowLayout());
           panel.add(lblAccountId);
           panel.add(txtAccountId);
           panel.add(lblPassword);
           panel.add(txtPassword);
           panel.add(btnLogin);
           panel.add(lblOutPut);
           setSize(300,200);
           setTitle("Vanisri");
           setVisible(true);
    
    
        }
        
        private class MyListener implements ActionListener{
            public void actionPerformed(ActionEvent e){
                
                lblOutPut.setText("Welcome Vani");
            }
        }
        
        public static void main(String[] args)
        {
            new AccountLogin();
        }
        
        
    }

  4. #4
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    use two loops to scan [][] array ;)

    Java Code:
    for(...)
    {
    for(...){}
    }
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    use two loops to scan [][] array ;)

    Java Code:
    for(...)
    {
    for(...){}
    }
    The OP wants to check for a valid combination of a login name and a corresponding password. A single loop would be enough and please don't beg for rep points.

    kind regards,

    Jos

  6. #6
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default

    Can u give me an example on how to do it?

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Roselicious View Post
    Can u give me an example on how to do it?
    Given your table[][] matrix, a possible user name and a password the following simple method checks whether or not the user name exists and if the password is valid:

    Java Code:
    public boolean check(String user, String password) {
       for (int i= 0; i < table[0].length; i++)
          if (table[0][i].equals(user))
             return table[1][i].equals(password);
       return false;
    }
    As you can see a single loop can do it: it checks all usernames until one is found; next it checks the corresponding password and returns true if they match, false otherwise.

    kind regards,

    Jos

Similar Threads

  1. I need examples using parallel arrays
    By dangerzone9k in forum New To Java
    Replies: 10
    Last Post: 04-04-2009, 04:11 PM
  2. [SOLVED] Parallel Arrays with Choice ComboBox - need assistance
    By Judoon_Platoon in forum Java Applets
    Replies: 14
    Last Post: 10-01-2008, 09:07 PM
  3. How to create multidimension arrays
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:47 PM
  4. parallel taglibs
    By zohar in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-04-2007, 04:38 PM
  5. how to create different arrays
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 11:07 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
  •