Results 1 to 6 of 6
Thread: getAccountIndex
- 04-01-2009, 06:31 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 17
- Rep Power
- 0
getAccountIndex
public static String getAccountIndex(String accountNumber){
...
}
This method accept an account number and find that account's index in the parallel arrays (you will only need to search the array of account numbers). Since the arrays are parallel, an account will have the same index in each array. Keep in mind that the account number is NOT the account's index in the arrays!
I want to create a method that searches for a particular index in an array using an account number that the user can input. I am unsure how to approach this.
- 04-01-2009, 07:44 PM #2
Senior Member
- Join Date
- Jul 2008
- Posts
- 125
- Rep Power
- 0
Ping
I considered a reply to this request,
but I kept coming up with simpler and
simpler algorithms to the point that I
thought, "anthonym2121 must have
figured this out already."
So now, I am reduced to pinging
anthonym2121 to find out, "Do you
still need help with this method?"Last edited by paul pasciak; 04-01-2009 at 07:46 PM.
- 04-01-2009, 08:07 PM #3
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Uh... Is this what you mean?
Java Code:public static int getAccountIndex(int accountNumber) { for(int i = 0; i < parallelArray.length; i++) { if(accountNumber == parallelArray[i]) return i; } return -1; }
- 04-01-2009, 08:50 PM #4
Member
- Join Date
- Apr 2009
- Posts
- 17
- Rep Power
- 0
- 04-01-2009, 08:51 PM #5
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Well, just remember you can't use == when comparing strings. Good luck. : )
- 04-01-2009, 10:55 PM #6
Member
- Join Date
- Apr 2009
- Posts
- 17
- Rep Power
- 0
I was thinking of having two parameter: one being the string, and the other an array of strings. Since I am comparing between two strings I used ".equals". The following errors in this code appear:
Error: accountNumber is already defined in getAccountIndex [line:99]
Error: incompatible types [line: 103]
found : java.lang.String
required: java.lang.String[]
Java Code:[B][line:99][/B] public static int getAccountIndex(String accountNumber, String accountNumber[]){ int result = -1; [B][line:103][/B] accountNumber = JOptionPane.showInputDialog("What is your account number?"); for(int i=0;i<accountNumber.length;i++){ if(accountNumber.equals(accountNumber[i])){ return i; } } return result; }


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks