I have a class named Rectangle.java. It is in a package “Geometry” together with Point.java and Line.java. But when I try to use Rectangle.java in my main program, MyRect.java, it gives me a “cannot find symbol” error, particularly the methods and sometimes the variables. I tried compiling just my Rectangle class and it compiled fine… And I tried the Line and Point classes on another program and it works fine… well probably because the Line and Point classes are from a book… I am just starting out in Java.
Rectangle.java
package Geometry;
public class Rectangle{
public Point[] corner = new Point[4];
public Rectangle(){
corner[0].setPoints(0,0);
corner[1].setPoints(1,0);
corner[2].setPoints(0,1);
corner[3].setPoints(1,1);
}
public Rectangle(double point1_x,double point1_y,double point2_x, double point2_y){
corner[0].setPoints(point1_x, point1_y);
corner[3].setPoints(point2_x, point2_y);
corner[1].setPoints(point2_x, point1_y);
corner[2].setPoints(point1_x, point2_y);
}
public Rectangle(final Rectangle oldRect){
corner[0] = oldRect.corner[0];
corner[3] = oldRect.corner[3];
corner[1] = oldRect.corner[1];
corner[2] = oldRect.corner[2];
}
public double getWidth(){
return corner[0].distance(corner[1]);
}
public static void printRectangle(final Rectangle rect){
for(int i= 0;i<4;i++){
System.out.println("Corner"+(i+1)+" X: "+rect.corner*.getX()+" Corner"+(i+1)+" Y:
"+rect.corner*.getY());
}
}
public String toString(){
return ("Name: "+name);
}
}
MyRect.java
import Geometry.*;
public class MyRect{
public static void main(String[] args){
Rectangle myRect = new Rectangle(0.0,0.0,2.0,1.0);
printRectangle(myRect);
}
}
and the errors:
MyRect.java:5: cannot find symbol
symbol : method printRectangle(Rectangle)
location: class MyRect
printRectangle(myRect);
^
1 error