-1

I get: 'unexpected type
required: variable
found : value' on the marked lines (*)

for (int i = 0; i < boardSize; i++) {
    for (int j = 0; j < boardSize; j++) {
        rows[i].getSquare(j) = matrix[i][j]; // * points to the ( in (j)
        columns[j].getSquare(i) = matrix[i][j]; // * points to the ( in
        int[] b = getBox(i, j);
        int[] boxCord = getBoxCoordinates(i + 1, j + 1);
        boxes[b[0]][b[1]].getSquare(boxCord[0], boxCord[1]);
    }
}

This is my Row class:

private Square[] row;

Row(int rowCount) {
    this.row = new Square[rowCount];
}

public Square getSquare(int index) {
    return this.row[index];
}  

Please help me out by pointing out what I'm doing wrong here.
Thanks in advance.

A.H.
  • 61,009
  • 14
  • 85
  • 115
jollyroger
  • 609
  • 1
  • 10
  • 19

3 Answers3

10

You cannot assign something to the return value of a method. Instead, you need to add a setSquare() method to the Row class:

public Square setSquare(int index, Square value) {
    this.row[index] = value;
}  

and use it like this:

rows[i].setSquare(j, matrix[i][j]);
Michael Borgwardt
  • 335,521
  • 76
  • 467
  • 706
0

Java doesn't have pointers - references are not the same thing.

It's impossible to tell what's really going on based on the code you posted. I think you need a method to set the value of that Square in the private array your Row class owns.

public void setSquare(int index, Square newSquare) {
    this.row[index] = newSquare; 
}

It looks like a poor abstraction, in any case.

duffymo
  • 299,921
  • 44
  • 364
  • 552
-2

Java has no pointers. Objects are passed and returned by reference. In terms of C++, rows[i].getSquare(j) is an rvalue, not an lvalue, so you cannot assign to it.

Instead, you should create and use rows[i].setSquare(...).

Alexander Pavlov
  • 30,691
  • 5
  • 65
  • 91