This assignment is designed to give you additional practice with nested loops. Also, it is awesome.
import java.util.Scanner;
public class LetterCube
{
public static void main( String[] args )
{
System.out.println("Welcome to the infamous Letter Cube!\n");
LetterCube cube = new LetterCube();
Scanner console = new Scanner( System.in );
String side;
do
{
System.out.print("Which side: ");
side = console.next();
if ( side.equals("front") )
cube.showFront();
else if ( side.equals("back") )
cube.showBack();
// etc
} while ( ! side.equals("quit") );
}
private String[][][] cube;
public LetterCube()
{
cube = new String[3][3][3];
char c = 'A';
for ( int L=0; L<3; L++ )
for ( int R=0; R<3; R++ )
for ( int C=0; C<3; C++ )
cube[L][R][C] = new String( "" + c++ );
// ^ ^ ^
// | | |
// | | +-- column
// | +----- row
// +-------- layer
}
public void showFront()
{
// layer fixed at 0, rows go forward, columns go forward
for ( int r=0; r<3; r++ )
{
for ( int c=0; c<3; c++ )
{
System.out.print( cube[0][r][c] );
}
System.out.println();
}
}
public void showBack()
{
}
}
Now write code to display what letters you would see looking at each of the six faces of the cube. Remember, you are looking at the outside of the cube, so (for example) the letters will appear to be in reverse order if you're looking at the back. You must use nested for loops for this assignment.
Welcome to the infamous Letter Cube! Which side: front ABC DEF GHI Which side: back UTS XWV [ZY Which side: left SJA VMD YPG Which side: right CLU FOX IR[ Which side: top STU JKL ABC Which side: bottom GHI PQR YZ[ Which side: quit