Help Please.... I am new in Java. I am trying to write a code that contains a class "point" into a public class "PeterAndSnowBlower" in Eclipse(Luna). I have also tried by making the variables x, y public in the class "point" and it gives the same error. I have also used this.x and this.y instead of x and y inside the constructors
Here is my code:
import java.util.*;
public class PeterAndSnowBlower {
class point{
int x;
int y;
public point() {
x = y = 0;
}
public point(int a, int b){
x = a;
y = b;
}
public point(point p) {
x = p.x;
y = p.y;
}
public double distance(point P){
int dx = x - P.x;
int dy = y - P.y;
return Math.sqrt(dx*dx + dy*dy);
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n, x, y;
point P = new point(0, 0);
n = in.nextInt();
P.x = in.nextInt();
P.y = in.nextInt();
Vector<point>points = new Vector<point>();
for(int i = 0; i < n; i++){
x = in.nextInt();
y = in.nextInt();
points.add(new point(x, y));
}
double r1, r2;
r1 = r2 = P.distance(points.get(0));
for(point point:points){
r1 = Math.max(r1, P.distance(point));
}
}
}
the error is:
Multiple markers at this line
- No enclosing instance of type PeterAndSnowBlower is accessible. Must qualify the allocation with an enclosing instance of type PeterAndSnowBlower (e.g.
x.new A() where x is an instance of PeterAndSnowBlower).
- The constructor PeterAndSnowBlower.point(int, int) is undefined