Any help would be greatly appreciated.
import java.util.Scanner;
public class Board
{
static int i; //variable to set rows and column equal to the same
static String sym; //symbol used to set entire array to same symbol
static String sym1; //symbol used with sym2 to alternate and create checkboard
static String sym2; //symbol used with sym1 to create checkerboard
static String sym3; //used in the insertSymbol method
static int r; //used in insertSymbol method. Represents row
static int c; //used in the insertSymbol method. represents column.
static Scanner in; //scanner variable called in
static String [][] Board; //declaring a string array called Board
public void setSize() //method to set the size of the array
{
System.out.println("Please enter a whole number to represent" +
"the length and width of your board.");
i=in.nextInt();
Board= new String[i][i];
}
public void placeSymbol() //method to place a symbol in every cell of the array
{
System.out.println("Please enter any character and" +
"this character will fill the board.");
sym = in.next();
for(int column = 0; column <i; column++)
for(int row = 0; row<i; row++)
Board[row][column]=sym;
}
public void placeSymbols() //method to place two symbols alternating in the array
{
int test;
System.out.println("Please enter a Character.");
sym1=in.next();
System.out.println("Please enter another character.");
sym2=in.next();
for (int row = 0; row < i; row++)
{
for (int col = 0; col < i; col++)
{
test = row + col;
if (test % 2 == 0)
{
Board[row][col] = sym1; // add character at even array position
}
else
{
Board[row][col] = sym2; // add character at odd array position
}
}
}
}
public void insertSymbol() //method to insert a specific symbol into a specific address of the array
{
System.out.println("Please enter the row number you"+
"want to insert at.");
r=in.nextInt();
System.out.println("Please enter the column number"+
"you want to insert at.");
c=in.nextInt();
System.out.println("Please enter the character you want"+
"inserted at that address.");
sym3=in.next();
Board[r][c]=sym3;
}
public void printBoard()
{
//Board someBoard=new Board();
/*String output = "";
for (int row = 0; row < i; row++) {
for (int col = 0; col < i; col++) {
output += sym;
}
output += "\n";
}*/
//someBoard.Board();
System.out.println(Board);
}
public static void main(String[] args)
{
//int action; //variable action used in switch staement
in = new Scanner(System.in);
boolean done = false;
Board someBoard=new Board();
System.out.println("Follow the instructions \n");
while (done!=true)
{
someBoard.printBoard();
someBoard.setSize();
someBoard.placeSymbol();
someBoard.printBoard();
someBoard.placeSymbols();
someBoard.insertSymbol();
someBoard.printBoard();
done = true;
}
}
}

New Topic/Question
Reply


MultiQuote




|