|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Array of type class?
Ok, I'm in the final stage of finishing up an application. I have been requested to create a class, that has one constructor with one parameter: an array of type Row, where Row is a class on my application.
So far I've got Code:
//Player.java
package nim;
public class Player implements NimPlayer{
private Row [] rows;
public ComputerNimPlayer(Row[] row){//will add some stuff here}
}
Does anyone know if that's the right format? Rigth now the error I'm getting is nim.Player is not abstract and does not override abstract method setBoard(nim.Row[]) in nim.NimPlayer |
|
#2
|
||||
|
||||
|
Yes, the code you've presented seems syntax-correct...
What does your NimPlayer object look like? When you implement an interface, you need to include all methods... even if you just want them empty.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
The only stuff on NimPlayer is
Code:
public Move selectMove();
public void setBoard (Row [] rows);
So am I supposed to include setBoard? I'm sorry I have to ask and not try it myself, but I'm still busy on the details of the other parts, but it would be great if you could help me figure out the syntax before I do some coding on Player.java BTW i noticed I was asked for a constructor, so I changed Code:
public ComputerNimPlayer(Row[] row){//will add some stuff here}
to Code:
public Player(Row[] row){//will add some stuff here}
|
|
#4
|
|||
|
|||
|
Well, the syntax is still not working. Here is what I've got so far:
Code:
package nim;
import java.util.Random;
public class ComputerNimPlayer implements NimPlayer{
Random random = new Random();
private Row [] rows;
public ComputerNimPlayer(Row[] row){
rows = new Row[1+random.nextInt(17)];
selectMove();
setBoard(rows);
}
public Move selectMove(){
int howmany = 1 + (new Random().nextInt(21));
return howmany;
}
public void setBoard(Row[] row){
}
}
Code:
// * NimPlayer.java
package nim;
public interface NimPlayer {
public Move selectMove();
public void setBoard (Row [] rows);
}
and the error I get is Quote:
I want private Row [] rows; to be the only data member for the class with a single parameter constructor that sets rows. So far I think the constructor and the select move method are OK, but that single error I'm getting it's driving me nuts. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Array of type class? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|