As suggested by Ahmed, you could also represent your cube as a tridimensional array.
The solution with two dimensions, will go along the lines of previous answers.
String[][] cube = {
{"red","red","red","red","red","red","red","red","red"},
{"blue","blue","blue","blue","blue","blue","blue","blue","blue"},
{"yellow","yellow","yellow","yellow","yellow","yellow","yellow","yellow","yellow"},
{"green","green","green","green","green","green","green","green","green"},
{"orange","orange","orange","orange","orange","orange","orange","orange","orange"},
{"white","white","white","white","white","white","white","white","white"}
}
This would replace your one, two, and so on, arrays.
Arrays are not that hard to understand.
Imagine a box, and that would be your everyday variable. String s, would be an example.
Awesome ASCII variable representation:
[«content»]
An array, in this analogy, would be a zero-indexed line of boxes. That is, you tell your program how many boxes are tied together in that line (the array length), and then you access the individual boxes by their number, for instance, a[index].
Awesome ASCII array representation:
[«content»][«content»][«content»] ... [«content»]
Box 0 Box 1 Box 2 Box (length-1)
In a two dimensional array, you now have lines and columns of boxes. Or, in other words, you have a matrix of boxes, or a rectangle of boxes, whatever you prefer. You access the individual elements by two indexes. For isntance, a[line][column].
Awesome ASCII matrix representation:
Lines/Columns 0 1 2 3 4 ...
0 [ ] [ ] [ ] [ ] [ ] ...
1 [ ] [ ] [ ] [ ] [ ] ...
2 [ ] [ ] [ ] [ ] [ ] ...
3 [ ] [ ] [ ] [ ] [ ] ...
4 [ ] [ ] [ ] [ ] [ ] ...
...
The above resembles a square, or a face of your cube.
Let's try now with three dimensions (I won't be able to write awesome ASCII art for that one).
String[][][] cube = {
// First face, a square, or a two-dimensional array
{
// First line
{"red", "red", "red"},
// Second line
{"red", "red", "red"},
// Third line
{"red", "red", "red"}
},
// Second face
{
// First line
{"blue", "blue", "blue"},
// Second line
{"blue", "blue", "blue"},
// Third line
{"blue", "blue", "blue"}
},
// Do the same for the four remaining faces.
}
With the above, you can access every single little square with ease.
Suppose, upon a rotation, that I want to change the three right vertical squares.
// For face f (0 .. 5), change 3rd column (2), in every line (0, 1, 2).
cube[f][0][2] = newcolor;
cube[f][1][2] = newcolor;
cube[f][2][2] = newcolor;
If you're interested in more, keep reading. If this suits your needs, you may stop reading here.
Even though it is not included in the scope of this question, if you stick with Java, later on you will want to learn about Enumerations.
Enumerations allow you to specify a fixed set of values, for later use. In your cube, the colors are a fixed set of values that you know beforehand (the colors are always the same six). You could then specify you Color type, as an enumeration.
public enum Color {
RED, BLUE, ORANGE, GREEN, YELLOW, WHITE
}
Instead of using Strings, you may now use your own colors. For instance, let's take the above example of a rotation in a tridimensional array, and assign the color red to face zero.
cube[0][0][2] = Color.RED;
cube[0][1][2] = Color.RED;
cube[0][2][2] = Color.RED;
This may seem as a lot to take in, for a beginner, and that's why I've put this in a different section of my answer.
When using Strings, if you type "rde", instead of "red", your program will go on, and you'll notice it only when it's too late already (ie, your program is already running and printing these erroneous values).
The main advantage with enum, is that if you type Color.RDE, your compiler will warn you, and won't compile your program until you fix that, which is a nice thing to have.