BLEH. Этот код будет просто завален проблемами, если всем будет разрешен доступ к одним и тем же изменчивым глобальным (!) Переменным. Как насчет чего-то вроде следующего, чтобы инкапсулировать то, что вы хотите:
public class Cube
{
private final float highX;
private final float lowX;
private final float highY;
private final float lowY;
private final float highZ;
private final float lowZ;
// TODO give domain-meaningful names to magic defaults for Y axis
public Cube(float highx, float lowx, float highz, float lowz)
{
this(highx, lowx, 4.5f, 2.5f, highz, lowz);
}
public Cube(float highx, float lowx, float highy, float lowy, float highz, float lowz)
{
// TODO - assert the "high" parameters are strictly greater than the "lows"
this.highX = highx;
this.lowX = lowx;
this.highY = highy;
this.lowY = lowy;
this.highZ = highz;
this.lowZ = lowZ;
}
// TODO add relevant getter methods, and interesting methods like:
public float getVolume()
{
return (highX - lowX) * (highY - lowY) * (highZ - lowZ);
}
...
}
public void addcube(Collection<? super Cube> cubes, float highx, float lowx, float highz, float lowz){
//Constructing new cube...
final Cube cube = new Cube(highx, lowx, highz, lowz);
System.out.println("ADDING A CUBE!!"); // FIXME is this really necessary?
// Note, adding to a specific collection of cubes rather than a
// hard-coded global variable
cubes.add(cube);
}
"Куб" - это странное слово, когда вы смотрите на него достаточно долго.