Again, i‘ll just answer
Q1:
You generally want to add final if you make a constant. For example :
final float SPEEDOFLIGHT = 3000000; // you‘ll never want to change that, cause the speedOfLight is a constant
//while
float velocity = 5; // you might want to change the velocity later on, so you don‘t declare it as final.
Final just means that the variable can’t be changed, which is exactly what you‘d want from a Constant. And generally constants are written all capitalized, just for convention…
As for what exactly that constant UNKNOWN stands for, it denotes what value your Flag should have, when you don‘t have anything flagged… Another example :
myFlag = -1;
if (myFlag != -1) { //so we have a flag value
// we can do something since we got a valid flag
}
// but using a constant is much smoother, since you never
// know if you have to change that -1 to something different...
final int UNKNOWN = -1;
int myFlag = UNKNOWN; //since we don‘t have a flag right at the start
If (myFlag != UNKNOWN) { //in this case, we can change what UNKNOWN means
// by changing the final int at the top, without having to look through all our code...
// do stuff
}
And we use -1, since your flag value can only be from 0 to 4 (5 discs in the array).
We could use any other value that those 5 numbers (0-4), but that‘s inconvinient if we want to suddenly have 100 discs and we used 44 as the UNKNOWN value… would be wierd, right?
Now we could use any negative value, but -1 is just the most obvious one… and you can just go to -2 if you need a second constant like NOTSURE, if you are not certain that discs overlap (doesn‘t make much sense in your case, but in other Codes that would be how it‘s used more or less).
As for Q2:
Relative Order always matters! But General Order not!
Now, relative Order would be this :
void draw() {
//this works
int a = 1;
int b = a+1;
int c = a+b;
//this doesn‘t work!
int d = e; //we still don’t have a variable e, even if we declare it later...
int e = 5; //we only declared it after d, so d couldn‘t have known about it before.
}
General Order :
float a = 1;
float e = 5;
float b = 19;
float z = 3;
//none are relative to each other, so the Order can be completely arbitrarily.
// As Long as you don‘t use them before you declare them like
float j = i+k;
float i = 9;
float k = 4;
//this won’t work!!!
That‘s pretty much all i‘d say…
I just noticed that Q2 isn‘t really answered all that well… so, no, as long as you don‘t use a variable that‘s not been declared before, you can Order the variables any way you want, doesn‘t matter where (Class, Global, Method).