Identifying objects in an ArrayList
in
Programming Questions
•
1 month ago
I have an ArrayList that is filled with different kinds of objects and I need those objects to interact ones with others.
So, I have an ArrayList called bacteria and inside it is storing objects BacteriaOne, BacteriaTwo, BacteriaThree and BacteriaFour. Now I want that the BacteriaOne objects combine with BacteriaTwo objects only, but I don't know how to differentiate one type from the other.
I'm using a for to detect the contact between bacteria, but of course I'm doing it wrong because it is taking all the four kinds of bacteria.
So, I have an ArrayList called bacteria and inside it is storing objects BacteriaOne, BacteriaTwo, BacteriaThree and BacteriaFour. Now I want that the BacteriaOne objects combine with BacteriaTwo objects only, but I don't know how to differentiate one type from the other.
I'm using a for to detect the contact between bacteria, but of course I'm doing it wrong because it is taking all the four kinds of bacteria.
- for (int i= 0; i<bacteria.size(); i++) {
- if (dist(bacteria.get(i).getPosX(), bacteria.get(i).getPosY(), bacteria.get(i).getPosX(), bacteria.get(i).getPosY())<30) {
- bacteria.remove(i);
- }
Now can someone please help me and tell me how can I differentiate when only BacteriaOne and BacteriaTwo make contact? Thanks in advance.
1