I'm trying to test a class I have written(I'm an absolute beginner!). I'm getting these errors:
These are the codes:
Punt.java :
and I'm trying to test Punt.java with TestPunt.java :
I'm probably doing something very stupid, could you please say what that stupid thing is that I'm doing and don't laugh :P
Thanks.
TestPunt.java:3 1: afstand() in Punt cannot be applied to (Punt) System.out.prin tln("p1.afstand (p2): "+p1.afstand(p2 ));
Punt.java:53: double cannot be dereferenced return (this.getX().eq uals(that.getX( )) && this.getY().equ als(that.getY() ));
Punt.java:49: double cannot be dereferenced return (this.getX().eq uals(that.getX( )) && this.getY().equ als(that.getY() ));
Punt.java :
Code:
public class Punt
{
private double xCoord;
private double yCoord;
public Punt(double x, double y)
{
xCoord = x;
yCoord = y;
}
public void setX(double x)
{
xCoord = x;
}
public void setY(double y)
{
yCoord = y;
}
public double getX()
{
return xCoord;
}
public double getY()
{
return yCoord;
}
public String toString()
{
String res = "<Punt(";
res = res + getX();
res = res + ",";
res = res + getY();
res = res + ")>";
return res;
}
public boolean equals(Object other)
{
if(other instanceof Punt)
{
Punt that = (Punt) other;
return (this.getX().equals(that.getX()) && this.getY().equals(that.getY()));
}
else
{
return false;
}
}
public double afstand() //distance
{
return Math.sqrt(getX()*getX()+getY()*getY());
}
}
Code:
public class TestPunt
{
public static void main(String []args)
{
Punt p1 = new Punt(1,2);
System.out.println("p1.getX(): " + p1.getX());
System.out.println("p1.getY(): " + p1.getY());
System.out.println();
System.out.println("p1.setX(4)");
p1.setX(4);
System.out.println("p1.getX(): " + p1.getX());
System.out.println();
System.out.println("p1.setY(6)");
p1.setY(6);
System.out.println("p1.getY(): " + p1.getY());
System.out.println("p1.toString(): "+p1.toString());
Punt p2 = new Punt(2,4);
System.out.println("p2.toString(): "+p2.toString());
System.out.println("p1.equals(p1): "+p1.equals(p1));
System.out.println("p1.equals(p2): "+p1.equals(p2));
System.out.println("p1.afstand(p2): "+p1.afstand(p2));
}
}
I'm probably doing something very stupid, could you please say what that stupid thing is that I'm doing and don't laugh :P
Thanks.
Comment