if you want the ability to have an instance created where one parameter is specified and it creates a square grid, or two parameters are specified and it creates a rectangle grid, if you want these two options, then you need the two constructors.
Java does not have default values for arguments like some other languages do.
if you want to have one constructor, you can try to create a static factory method.
|
Code:
|
public static NQueens getSquareGrid(int size) {
return new NQueens(size, size);
} |
where here we removed the one argument constructor with this method that just calls the two argument one with the same argument twice.