createPieceFactory(Random r)

Hi! I’ve implemented a class that implements PieceFactory, but now I can’t just figure out how am I supposed to use this random number generator (Random r). Did I get it right that in createPieceFactory I should basically just return an instance of the class that implements interface PieceFactory?

You have to pass the random number generator Random r to your PieceFactory cause you will have to use it in the getNextRandomPiece() method of your PieceFactory implementation.

You could do that in the constructor:

public PieceFactory(Random r) {

or any other way.

That is open to you. But it is important (for the tests) that you use the given random number generator Random r in your implementation. Otherwise you will fail some tests (I forgot to add it and failed some tests).

1 Like