Setting up DrJava to work through Friedman / Felleisen "A Little Java"
        Posted  
        
            by JDelage
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by JDelage
        
        
        
        Published on 2010-04-01T14:55:39Z
        Indexed on 
            2010/04/01
            15:03 UTC
        
        
        Read the original article
        Hit count: 467
        
All,
I'm going through the Friedman & Felleisen book "A Little Java, A Few Patterns". I'm trying to type the examples in DrJava, but I'm getting some errors. I'm a beginner, so I might be making rookie mistakes.
Here is what I have set-up:
public class ALittleJava {
  //ABSTRACT CLASS POINT
  abstract class Point {
    abstract int distanceToO();
  }
  class CartesianPt extends Point {
    int x;
    int y;
    int distanceToO(){
      return((int)Math.sqrt(x*x+y*y));
    }
    CartesianPt(int _x, int _y) {
    x=_x;
    y=_y;
    }
  }
  class ManhattanPt extends Point {
    int x;
    int y;
    int distanceToO(){
      return(x+y);
    }
    ManhattanPt(int _x, int _y){
      x=_x;
      y=_y;
    }
  }
}  
And on the main's side:
public class Main{
  public static void main (String [] args){
    Point y = new ManhattanPt(2,8);
    System.out.println(y.distanceToO());
  }
}
The compiler cannot find the symbols Point and ManhattanPt in the program.  
If I precede each by ALittleJava., I get another error in the main, i.e., 
an enclosing instance that contains ALittleJava.ManhattanPt is required
I've tried to find ressources on the 'net, but the book must have a pretty confidential following and I couldn't find much.
Thank you all.
JDelage
© Stack Overflow or respective owner