PDA

Click to See Complete Forum and Search --> : class error?


Striver2000
Mar 10th, 2004, 09:27 AM
Here is the problem I have the code for this class below: In the method isvalid I want to check to see if the islegalmove is not true and if its not then return the string notvalid. I am using blue j to write this program and when I compile the code I get this message '.class' expected Here is the code can someone please help

[java]:

public class ColorsRules extends Rules
{
private Sting notvalid;


public ColorsRules()
{
isvalid="This entry is not valid, please try again";
}


public String isvalid()
{
if(!isLegalMove(int player, int c1, int r1, int c2, int r2))
{
return notvalid;
}
}


public boolean isLegalMove(int player, int c1, int r1, int c2, int r2)
{
if (!(Board.isOrthogonal(c1, r1, c2, r2) || Board.isDiagonal(c1, r1, c2, r2))) return false;
if (!Board.isCloseEnough(4, c1, r1, c2, r2)) return false;
// check that each designated square is non-empty
int dx = sign(c2, c1);
int dy = sign(r2, r1);
int distance = Board.distance(c1, r1, c2, r2);
for (int i = 0; i <= distance; i++)
{
if (board.isEmpty(c1 + i*dx, r1 + i*dy)) return false;
}

return true;
}

}

Dillinger4
Mar 10th, 2004, 11:01 PM
Try using the code tags to make your code easier to read. All your indents will be preserved when you use them. Are all of the methods that are contained within the Board class declared static? Seems you are making static method calls. Also around the last line you have board rather than Board.



public class ColorsRules extends Rules {

private String notvalid;

public ColorsRules() {
isvalid="This entry is not valid, please try again";
}

public String isvalid() {
if(!isLegalMove(int player, int c1, int r1, int c2, int r2)) {
return notvalid;
}
}

public boolean isLegalMove(int player, int c1, int r1, int c2, int r2) {

if (!(Board.isOrthogonal(c1, r1, c2, r2) || Board.isDiagonal(c1, r1, c2, r2))) return false;
if (!Board.isCloseEnough(4, c1, r1, c2, r2)) return false;
// check that each designated square is non-empty
int dx = sign(c2, c1);
int dy = sign(r2, r1);
int distance = Board.distance(c1, r1, c2, r2);

for (int i = 0; i <= distance; i++) {
if (board.isEmpty(c1 + i*dx, r1 + i*dy)) return false;
}
return true;
}
}