Hey all,
I've hit a snag with a question and am hoping for a little guidance. In the question I am supposed to create a grid and have a user inputted character to fill up the space of the grid.
ex. 4X4 with $
$$$$
$$$$
$$$$
$$$$
Now, so far I've started out and think that I may be veering down the wrong path. I've created my methods and am not sure that the placeSymbol one is right. My code so far is:
Code:
import java.util.*;
public class Board
{
// variables
int x;
int y;
String symbol1;
String[][] twoDArray;
// default constructor
public Board()
{
x = 0;
y = 0;
symbol1 = "";
String[][] twoDArray = new String[100][100];
}
// constructor
public Board(int newRow, int newCol, String newSymbol1)
{
x = newRow;
y = newCol;
symbol1 = newSymbol1;
String[][] twoDArray = new String[x][y];
}
public int placeSymbol()
{
String[][] twoDArray = new String[x][y];
for(int i = 0; i < x; i++)
{
for(int j = 0; j < y; j++)
{
twoDArray[i][j] = symbol1;
}
}
return 0;
}
public void printBoard(String[][] twoDArray)
{
for(int i = 0; i < x; i++)
{
for(int j = 0; j < y; j++)
{
System.out.println();
}
System.out.println("" + twoDArray[x][y]);
}
System.out.println();
}
public static void main(String[] args)
{
Board twoDArray;
twoDArray = new Board(8, 8, M);
twoDArray.printBoard();
}
}
My driver at the end isn't what the final product will be. I just quickly wrote it up to try and print out my board. Needless to say, there is an error there. It doesn't recognize the symbol 'M' in this case. This is why I know there are problems somewhere in my code but don't know where. I would be most thankful for any guidance.
Thanks