This site requires JavaScript, please enable it in your browser!
Greenfoot back
Avik
Avik wrote ...

2013/5/17

whats wrong with this?

1
2
Avik Avik

2013/5/17

#
for (Object obj : getObjects(Coin.class)) { Coin coin = (coin)obj; coin.setLocation(coin.getX()+4x);, (coin.getY()+3y); }
Gevater_Tod4711 Gevater_Tod4711

2013/5/17

#
Well this line: coin.setLocation(coin.getX()+4x);, (coin.getY()+3y); should probably be: coin.setLocation(coin.getX()+4x, coin.getY()+3y); And I think your foreach loop will not work this way. I'm not shure why but every time I try to do this it doesn't work. Probably because it's a method call and not an object with an Iterator. But if you do it like this:
List<Object> objects = getObjects(Coin.class);
for (Object obj : objects) { 
    Coin coin = (coin)obj;    
    coin.setLocation(coin.getX()+4x, coin.getY()+3y); 
}
it should work.
Avik Avik

2013/5/17

#
what does ')' expected mean because its asking for one between 4 and x
Gevater_Tod4711 Gevater_Tod4711

2013/5/17

#
It means that there should be a ')'. Probably because of the x following the 4. Why did you write this x and y after the numbers?
Avik Avik

2013/5/17

#
what does it mean by cannot find symbol- class list
Avik Avik

2013/5/17

#
thankyou very much
Gevater_Tod4711 Gevater_Tod4711

2013/5/17

#
If you want to use the class List you first have to import it. So after the greenfoot import (at the top of your code) you have to write this: import java.util.List;
Avik Avik

2013/5/17

#
sorry to bug you, thanks for the anwer, what does cannot find symbol- variable x4. sorry I just started greenfoot lastweek so really stuck! sorry again
Gevater_Tod4711 Gevater_Tod4711

2013/5/17

#
You don't need to be sorry. It's ok. Nowone knows everyting about a programming language if he just starts learning it. The error means that x4 is a name for a variable. (because it's no number or no java keyword like if, while, for, ... So you the compiler searches for the variable x4 but there is no such variable in your code. What do you expect the x4 for? If you want your coin to move 4 cells in x direction just use +4 without the x. (also without y)
Avik Avik

2013/5/17

#
okay thanks
Avik Avik

2013/5/17

#
List<Object> objects = getObjects(coin.class); for (Object obj : objects) { coin coin = (coin)obj; coin.setLocation(coin.getX()+3);,(coin.getY()+3); } is this okay
Gevater_Tod4711 Gevater_Tod4711

2013/5/17

#
Yea I think this should work.
Avik Avik

2013/5/17

#
between the ; and the , it says illegal start of expression
danpost danpost

2013/5/17

#
There is nothing wrong with using the following (without having to import the List class):
for (Object obj : getObjects(Coin.class)) {
    Coin coin = (Coin)obj;    
    coin.setLocation(coin.getX()+3, coin.getY()+3); 
}
Avik Avik

2013/5/17

#
that doesn't work danpost
There are more replies on the next page.
1
2