Share Pastebin
Guest
Public paste!

Alexander

By: a guest | Feb 9th, 2010 | Syntax: Java | Size: 1.45 KB | Hits: 23 | Expires: Never
Copy text to clipboard
  1. public class Point
  2. {
  3.     /** Decleration of variables */
  4.     private int Id = 0; // the unique id for the instance of the class
  5.     static int counter = 0; // the counter of how many classes made
  6.     static List classList = new List(); // creates new list to store all the class instances
  7.     private double coord_x, coord_y;
  8.    
  9.     /**
  10.     Description: This constructor will run when new instance of this class is
  11.                  created and no values for x and u are specified
  12.     */
  13.     public Point()
  14.     {
  15.         this(0.0,0.0);
  16.     }
  17.    
  18.    
  19.     /**
  20.     Description: This constructor will run when new instance of this class is
  21.                  created and gets specified values for x and y
  22.     @param x (double), the value of x coordinate
  23.     @param y (double), the value of y coordinate
  24.     */
  25.     public Point(double x, double y)
  26.     {
  27.         this.coord_x = x;
  28.         this.coord_y = y;
  29.         classList.set(this.Id,this); // this is what i am trying to get to work
  30.         this.Id = this.counter++;
  31.     }
  32. }  
  33.  
  34. // i am trying to keep track of all classes so i can have a method within this class that will print all my x, y and the Id of the class
  35. // My idea was to add the refrence of the class to a list and then use for loop to print them all out.
  36.  
  37. //Error
  38. Point.java:47: cannot find symbol
  39. symbol  : variable This
  40. location: class Point
  41.         classList.set(this.Id,This);
  42.                               ^
  43. 1 error