I have the following code:
// test program
public class Array
{
private final static int ROW = 3;
private final static int COL = 3;
private static String[][] weStatementLines = ;
public Array(String[][] weStatementLines)
{
this.weStatementLines = weStatementLines;
}
public String[][] getArray()
{
return weStatementLines;
}
public void setArray()
{
this.weStatementLines = weStatementLines;
}
}
// test program
public class TestArray
{
public static void main(String[] arg)
{
String[][] size = { {"me"}, {"this"}, {"it"}, {"456"}, {"then"} };
Array New = new Array(size);
String[][] One = New.getArray();
System.out.println("array size = " + One.length);
for (int i = 0; i < One.length; i++)
{
System.out.println(One);
}
}
}
I'm trying to guarantee that when an Array object is created that the only valid Array that will be accepted will be a 3x3 array. How would I do this? I could check the array used to instantiate the class and throw an exception but is this the better way to do it? Thanks for any help in advance.
// test program
public class Array
{
private final static int ROW = 3;
private final static int COL = 3;
private static String[][] weStatementLines = ;
public Array(String[][] weStatementLines)
{
this.weStatementLines = weStatementLines;
}
public String[][] getArray()
{
return weStatementLines;
}
public void setArray()
{
this.weStatementLines = weStatementLines;
}
}
// test program
public class TestArray
{
public static void main(String[] arg)
{
String[][] size = { {"me"}, {"this"}, {"it"}, {"456"}, {"then"} };
Array New = new Array(size);
String[][] One = New.getArray();
System.out.println("array size = " + One.length);
for (int i = 0; i < One.length; i++)
{
System.out.println(One);
}
}
}
I'm trying to guarantee that when an Array object is created that the only valid Array that will be accepted will be a 3x3 array. How would I do this? I could check the array used to instantiate the class and throw an exception but is this the better way to do it? Thanks for any help in advance.