This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm trying to have each shape that's in the array move around the canvas randomly and independently. When the shape (array[i]) goes out of the canvas, it should be reset in another random location to continue moving once again. Can anyone tell me what's wrong with this code?
The "Driver" class draws the shapes from the class Star on to the canvas.
That is a lot of code to expect someone to go through, and not much info on where to look. Can you simply/reduce the amount of code you post but still demonstrate the issue? Preferably one we can compile and run as-is.
Generally speaking, when stuff isn't working how I think it should, I start sticking in System.out.println() statement. Put them in at the top and bottom of each method telling me that I am entering/leaving. Put them in each time you change a variable. Put them in at the top of a loop. Put them in before each IF statement, or in each block of the If/else if/else block.
eventually, you can narrow down where the problem is, and figure out why something isn't changing that should, or is changing that shouldn't.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Whenever theres trouble, debug it.
If you a beginner, you may take my recommendation
If you are on console, go for System.out.println statements as Fred insisted, and if you're with an IDE, add debug points to important locations and run the program in debug mode, and see that the variables are having what values! And you will be on track again!
And yes, this big code is very hard to read in a short span, so its recommended for OP to show some research effort and narrow down the question to specific issues!