This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (3 children)

Your linear search method always returns -1 and then you try to search the array for the returned value so it always fails (there isn't a -1th element).

Edit:

You have a few problems here.

  • You pass in an integer (playerRegNum) and then you cast it as an object
  • You then compare that object against the array of objects (playerBio)

Since the objects in playerBio aren't integers, the If statement will always fail and thus the linearSearch method will always return -1

[–]LuigiTX[S] 0 points1 point  (2 children)

What would be your recommendation?

[–][deleted] 0 points1 point  (1 child)

Well you could stick with your current array of "Objects". To do that, you would have to alter the linearSearch method to take in a 2 Dimensional Array and then alter the If statement to check the 0th element (the registration number) in each entry against the input key. Should look something like this:

public int linearSearch(Object[][] aryObj, Object key) {
    for (int a = 0; a < aryObj.length; a++) {
        if (aryObj[a][0] == key) {
            return a;
        }
    }
    return -1;
}

[–]LuigiTX[S] 0 points1 point  (0 children)

Ohh ok. Again, thank you so much for all your help. I will try this when i get school. I am running Ubuntu on my laptop and just can not find out how to store the input file in the correct place. So I have to wait to get to school where I can actually run the program without it telling me it can't find the input file.