わかりましたので、次の方法について本当に助けが必要です。開始方法が本当にわかりません。
クラスには setRowColumn メソッドが必要です。これには 3 つの引数が必要です。行と列を指定する 2 つの整数と、1 つの文字です。このメソッドは、ボード上の指定された場所に文字を保存します。クラスには getRowColumn メソッドが必要です。これは、行と列の 2 つの整数引数を取ります。このメソッドは、その位置にある文字を返します。クラスには toString メソッドが必要です。このメソッドは、ボードの内容を含む文字列を作成します。ボードの各行は、文字列の 1 行になります。ボードの上下に - を使用し、両側に | を使用して、ボードの周囲に境界線を引きます。各コーナーに + を入れます。以下は私が完成したものです.2つのクラスで私を助けてくれれば、私のtoStringメソッドもチェックしてください. ありがとうございました。
public class Board {
private char [][] theBoard;
public Board() { // This will not take any arguments
this(10, 25); // calls the other constructor
}
// takes number of rows and columns
public Board (int rows, int cols) {
// fix illegal row and column numbers
if (rows < 1 || rows>80) {
rows = 1;
}
if (cols<1 || cols > 80) {
cols = 1;
}
// create the board and fill it with ' '
theBoard = new char [rows][cols];
for (int row = 0; row < theBoard.length; row++) {
for (int col = 0; col < theBoard[row].length; col++)
theBoard[row][col] = ' ';
}
}
// only puts ' ' into fields not containing any of '0' - '9'
public void clearBoard() {
for (int row = 0; row < theBoard.length; row++ ) {
for (int col = 0; col < theBoard[row].length; col++) {
if (theBoard[row][col] < '0' || theBoard[row][col] > '9') {
theBoard[row][col] = ' ';
}
}
}
}
public void setRowColumn(int row, int col, char character) {
int index = 0;
for ( int i = 1; i <= row; i++ )
if ( col[i] > col[index] )
index = i;
return index;
}
public String toString() { //begin toString method
int i;
String temp = new String (""); //create string
// drawLine
String line = "";
char topBottom = '-';
int k;
int row2 = theBoard[0].length;
for ( k = 0 ; k < row2 ; k++ ){
line += topBottom; // adding hyphens
}
System.out.println('+' + line + '+'); // adding left and right + corners
for (i=0; i<theBoard.length; i++) {
temp += "|"; //add characters to the string
for (int j=0; j<theBoard[0].length; j++) {
temp = temp + theBoard[i][j] + "|"; //add the actual number to the string
}
temp += "\n";
}
return line + "\n" + temp + "\n" + line; //return string
}// end of method toString
}