Results 1 to 2 of 2

Thread: class error?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    Baltimore
    Posts
    61

    class error?

    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;
    }

    }
    Striver2000

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

    Code:
     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;
     }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width