1

well I have an interaface called AbstractPlayer

package gr.auth.ee.dsproject.crush.player;

import gr.auth.ee.dsproject.crush.board.Board;

import java.util.ArrayList;

public interface AbstractPlayer
{
    public void setId (int id);

    public int getId ();

    public void setName (String name);

    public String getName ();

    public void setScore (int score);

    public int getScore ();

    public int[] getNextMove (ArrayList<int[]> availableMoves, Board board);

}

and the class that i have to make called RandomPlayer

package gr.auth.ee.dsproject.crush.player;


public class RandomPlayer implements AbstractPlayer 
{

int id;
String name;
int score;
public RandomPlayer () {

}
public RandomPlayer (Integer pid) {
    id=pid;
}
public int getId (){
    return id;
}
public String getName (){
    return name;
}
public int getScore (){
    return score;
}
public void setId(int idSet){
    id=idSet;
}
public void setName(String nameSet){
    name=nameSet;
}
public void setScore(int scoreSet){
    score=scoreSet;
}



public int[] getNextMove (ArrayList<int[]> availableMoves, Board board) {
    int k;
    k=availableMoves.size();
    int randMove;
    randMove=(int)(Math.random()*k);
    int[] arrayMyMove;
    arrayMyMove= new int[3];
    arrayMyMove=getRandomMove(availableMoves , randMove);
    int[] arrayReturn;
    arrayReturn = new int[4];
    arrayReturn[0]=arrayMyMove[0];
    arrayReturn[1]=arrayMyMove[1];
    int movement=arrayMyMove[2];
    if (movement==0) {
        arrayReturn[2]=arrayReturn[0]-1;
    } else if (movement==2) {
        arrayReturn[2]=arrayReturn[0]+1;
    } else if (movement==1) {
        arrayReturn[3]=arrayReturn[1]-1;
    } else if (movement==3) {
        arrayReturn[3]=arrayReturn[1]+1;
    }
    return arrayReturn;
}

and i get this error

The type RandomPlayer must implement the inherited abstract method AbstractPlayer.getNextMove(ArrayList, Board)

and also on the line that i implement the method getNextMove i get this error Multiple markers at this line - ArrayList cannot be resolved to a type - Board cannot be resolved to a type

Can someone tell me what is my mistake?

2 Answers 2

1

You need to import a class in every class which uses it.

You can't assume that just because a parent class imports a class that your sub-class also imports a class.

In short, import ArrayList and Board as you did in the first class.

Sign up to request clarification or add additional context in comments.

1 Comment

@JimGeor It would make sense for Java to have transient imports esp as they really have to be the same in 99% of cases, but it doesn't. BTW your IDE should be able to manage your imports for you so you don't need to worry about them.
0

From JavaDocs

When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract.

Please read here

http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.