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

2018/9/21

changeLocation() random (x, y) coordinates

cathamelia cathamelia

2018/9/21

#
For an assignment I need to write the body for a changeLocation() method. this is what the instructions say: "The changeLocation method sets the location of the Button object to a new (x, y) coordinate selected at random. The x coordinate must be selected from the range 100 to 500 inclusive, and the y coordinate must be selected from the range 100 to 300 inclusive." But everything I'm trying isn't working? I don't know how to set the locations to the random numbers or how to specify which one is x and which one is y. A classmate helped me and said "100+ Greenfoot.getRandomNumber(500-100+1)) for x and (100+ Greenfoot.getRandomNumber(300-100+1)) for y." But I can't figure out what format to put that in because everything i'm trying isn't working.
danpost danpost

2018/9/21

#
Please show what you tried. That way we can instruct you in such as manner that you may learn from where you were going awry.
You need to login to post a reply.