445,678 Members | 1,144 Online Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

 P: 2 I'm trying to test a class I have written(I'm an absolute beginner!). I'm getting these errors: 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 = "";         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());     }   } and I'm trying to test Punt.java with TestPunt.java : 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. Oct 19 '08 #1
3 Replies

 P: 2 No need to reply anymore, I already solved it :D Thanks anyways. Oct 19 '08 #2

 Expert 100+ P: 2,364 Hey there Punt Tester! An absolute beginner also, can you tell us what you are trying to ahve thr program do. What are you testing for, and what will the results be? Sorry for your troubles, hope you get working! Nov 18 '08 #3

 Expert 10K+ P: 11,448 Hey there Punt Tester! An absolute beginner also, can you tell us what you are trying to ahve thr program do. What are you testing for, and what will the results be? Sorry for your troubles, hope you get working! Just read the compiler error diagnostic messages, they're a giveaway: - method afstand() doesn't take any parameters; - getX() and getY() return primitives; primitives don't have methods. kind regards, Jos Nov 18 '08 #4 