I am very new to Java programming in general and have just started using 2D arrays. What I am trying to do is make a program that creates a chessboard 8x8, and asks the user to input strings (pieces) to be stored on the chessboard. For now, I dont want to check whether or not the piece is a valid chess piece, but I want to make sure that the placement is valid (i.e. when prompted to place a piece and the user chooses an invalid coordinate, the program will tell the user that its wrong). Otherwise, if the coordinate is right, it will store the string, which I will use another class to print the string(s) and output them, as well as where they are placed, to the user. Since it is a chess board, I am trying to convert 8x8 to 8 followed by a character from a-g.
Heres what I have so far:
public class ChessBoard {
public static void main(String[] args) {
char rows = 'a';
String spot;
int[][] grid = new int[8][8];
for (int i = 0; i < grid.length; i++, rows++) {
for (int col = 0; col < grid[i].length; col++) {
System.out.print(rows + "" + (col + 1) + " ");
}
System.out.println();
}
}
}
This prints the layout of the chessboard, but I am not sure how to ask the user for a string in a valid coordinate, say, e5, which can then be printed in another class.
I would want my expected output to be something like:
Enter a coordinate: a5
Enter a piece to be placed here: Queen
Continue until the user wishes to see what they have placed:
You have placed a Queen at a5
Any help would be appreciated, thanks!