B Whitehead B Whitehead - 1 month ago 6
Java Question

Implement my own Array Method Help Java

How would I implement my own method on an element of my own array?

for example, im trying to make a inventory system that if (INVENTORY[X].isValidID() == TRUE)

Then it returns true,

how would i do that?

public void addInv(int ITEM_ID) {
for(int x = 0; x < MAX_STORAGE; x++) {
if(INVENTORY[x].isValidID() == true ) {

}
}
}

public static boolean isValidID(int X) {
return true;
}

Answer

You are likely looking for something like this.

 public void addInv(int ITEM_ID) {
    for(int x = 0; x < MAX_STORAGE; x++) {
       if(isValidID(INVENTORY[x])) {

      }
    }
}

public static boolean isValidID(int X) {
   return true;
}