I tried writing a code similar to the one below, but I got a compiler error.
error: constructor Point in class Point cannot be applied to give types;
Why is the error displayed on line 28?
Please explain.
class Point {
private double x;
private doubley;
public void constructor() {
This.x = x;
This.y = y;
Point p = new Point (2.0, 5.0);
}
public double getX(){
return x;
}
public double getY(){
return;
}
public String to String() {
return "<Point("+x+", "+y+")>";
}
public void translate (double dx, double d) {
x = x + dx;
y = y + dy;
}
public double distance (Point other)
{
Point that = (Point) other;
double dist = Assignment1_7.distance(this.x, that.x, this.y, that.y);
return dist;
}
public boolean equals (Object other) {
if(this==other){
return true;
}
if (other instance of Point) {
Point that = (Point) other;
return(this.x==that.y&&this.y==that.y);
}
else
return false;
}
}
This is because you are calling a constructor that does not exist on the next line.
Point p = new Point (2.0, 5.0);
Perhaps you need a constructor similar to the following
publicPoint(double x, double y){
This.x = x;
This.y = y;
}
I didn't know what you meant, but I think the constructor()
method is probably unnecessary for this class.
© 2024 OneMinuteCode. All rights reserved.