Skip to content

Get cubeArr

Akshath Raghav edited this page Jun 28, 2021 · 1 revision

cubeToArr()

--> returns the cube in the form of a String[] ( as given in the input )

String[] temp2 = {"RRRR", "GGGG", "OOOO", "BBBB", "WWWW", "YYYY"};
Cubot cube = new Cubot(temp2) ;
String[] cubeInput = cube.cubeToArr() ;
for (String i : cubeInput) {
    System.out.print(i + " ");
}
System.out.println();
String[] temp  = {"RRRRRRRRR", "GGGGGGGGG", "OOOOOOOOO", "BBBBBBBBB", "WWWWWWWWW", "YYYYYYYYY"};
cube = new Cubot(temp) ;
cubeInput = cube.cubeToArr() ;
for (String i : cubeInput) {
    System.out.print(i + " ");
}

example

Why is this useful?

Say we want to copy a Cubot to another. Now, we don't have to do the lengthy input process again. Instead, all we have to do is call the cubeToArr() method and directly insert it into the constructor of another Cubot.

Let me show you -

String[] temp2 = {"RRRR", "GGGG", "OOOO", "BBBB", "WWWW", "YYYY"};
Cubot cube = new Cubot(temp2) ;
System.out.println();
String[] test = cube.cubeToArr() ;
Cubot cube2 = new Cubot(temp2) ;
System.out.println("cube and cube2 are the same ? -- " + cube.compareTo(cube2)); // -- true