Ok So I have a project for school and i'm stuck on arraylist. I have a abstract class called superhero that has getSuitColor, setCape, isCaped(boolean) and setSuitColor. I've already made objects out of my classes and made and ArrayList out of them. But Now I'm trying to remove the superhero with capes.
for ( int i = 0; i < heros.size(); i++)
if(heros.isCape() == true)
This is way I have but its not working cause it says "cannot find symbol - method isCape()"
I've been siting here for 40 minutes trying to figure it out but I can't :[
The ArrayList 'heros' does not have an isCaped() method. The various superhero objects in that List do.
So you want to use the get() method to return the superhero at index 'i' and then call the isCaped() method on that.
you don't need the '== true' part.
if (heros[i].isCaped() == true)
An 'if' statement simply requires a boolean to work with, which is what is returned by isCaped(), so no need to compare it with 'true'.
If heros is an ArrayList, Should that be:
I actually meant to copy the code in the OP, but mucked up...doubly so!