HELP! Need to know if there is a better way to find,based on a three-digit member id (memId) a record of a first name, last name....etc and alter one aspect (be it first name, membership fee...etc) of it. Im having trouble finding the code that will match up the answer with the name. The problem area is towards the end, line 214 to 247.
As I recall, the information in all of these arrays correspond by index. For example, the person with member ID memId has a first name of fname, and an age of age, and so on, right?
So I think you're asking how to find the index of an element in an array. That is, you have an int array called memId, and you're given a 3-digit number, and you want to find the index in memId that holds that number. Once you have this index, you will know the position to edit in all the other arrays.
The order of elements is critical in your arrays, so you cannot use Arrays.binarySearch (because this search requires a sorted array). So basically, you need to iterate through the array until you've found a match.
I suggest writing your own search method that returns the index of a certain member ID. The method would just iterate through the memId array, looking for a match of the input ID number. As soon as it finds a match, it would return the index number. If no match is found, it should return some special value (like -1) to indicate no match.
Does that help?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Jul 26, 2006
Boy your'e in trouble when someone on the board recognizes the monstrosity you've been struggling with.
I have several arrays, first name (fname) last name (lname).....and so on. I can code a menu with the best of them. I can even parse it into an integer. My problem is, if i ask a user (enter memberid) and they enter a 3 digit number, ill ask them what do they want to change (again...first name...last name) and I pretty much know the END of that story....something like
But ive tried just about everything to get fname[i] to match the 3-digit memId the user enters. Thats all the help i need. Once i have that....its off to the races. And i can handle it if its a double or an int (which i will be dealing with with other arrays).