lucian_x098
lucian_x098

Reputation: 35

Inherit methods from abstract class error

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?

Upvotes: 1

Views: 305

Answers (2)

Kevin Morocco
Kevin Morocco

Reputation: 179

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

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533500

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.

Upvotes: 1

Related Questions