TestPunt.java:31: afstand() in Punt cannot be applied to (Punt) System.out.println("p1.afstand(p2): "+p1.afstand(p2));
Punt.java:53: double cannot be dereferenced return (this.getX().equals(that.getX()) && this.getY().equals(that.getY()));
Punt.java:49: double cannot be dereferenced return (this.getX().equals(that.getX()) && this.getY().equals(that.getY()));These are the codes:
Punt.java :
Expand|Select|Wrap|Line Numbers
- 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());
- }
- }
Expand|Select|Wrap|Line Numbers
- 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.