This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
.\Cat.java:26: cannot find symbol
symbol : variable selectedMouse
location: class java.util.ArrayList<Mouse>
mouseWeight = Mammal.getWeight(mice.selectedMouse);
^
.\Mouse.java:44: cannot find symbol
symbol : variable mouse1
location: class java.util.ArrayList<Mouse>
boolean mouse1Sex = Mammal.getIsMale(mice.mouse1);
^
.\Mouse.java:45: cannot find symbol
symbol : variable mouse2
location: class java.util.ArrayList<Mouse>
boolean mouse2Sex = Mammal.getIsMale(mice.mouse2);
I have declared these variables already inside the same method, so there is no issue with it being accessible or not.
And getIsMale shouldn't be a static method in Mammal, it should be an instance method of a Mammal.
Why do you construct a new Mammal in Mouse:8?
In any case--it still looks like you're just writing random code with the hope that it will compile and work. You really need to take a step back, write a *small* amount of code, make sure it compiles, make sure it does what you want, and move forward from there. Trying to fix *all* the problems at once is a sub-optimal solution (and there are a *lot* of problems here).
Make it easier on yourself and stop trying to do everything at once.
Ben Hultin
Ranch Hand
Joined: Aug 17, 2009
Posts: 135
posted
0
mice is declared as ArrayList .... ArrayList dos not have field named 'mouse1'
so how wpuld I go about giving ArrayList a field named 'mouse1'. Are you meaning to say that it is trying to access an element inside the array called mouse1? How would define the arraylist to access an index number that is stored inside a varaible?
Ben Hultin wrote:so how wpuld I go about giving ArrayList a field named 'mouse1'. Are you meaning to say that it is trying to access an element inside the array called mouse1? How would define the arraylist to access an index number that is stored inside a varaible?
Click on any of the many ArrayList links that the JavaRanch forum provided for you, in this topic. They go to the JavaDoc which describes the methods that does exactly what you want.