By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

Testing a class and a couple of errors! please help.

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
  1. public class Punt
  2. {
  3.  
  4.     private double xCoord;
  5.     private double yCoord;
  6.  
  7.     public Punt(double x, double y)
  8.     {
  9.         xCoord = x;
  10.         yCoord = y;
  11.     }
  12.  
  13.     public void setX(double x)
  14.     {
  15.         xCoord = x;
  16.     }
  17.  
  18.     public void setY(double y)
  19.     {
  20.         yCoord = y;
  21.     }
  22.  
  23.     public double getX()
  24.     {
  25.         return xCoord;
  26.     }
  27.  
  28.     public double getY()
  29.     {
  30.         return yCoord;
  31.     }
  32.  
  33.     public String toString()
  34.     {
  35.         String res = "<Punt(";
  36.         res =  res + getX();
  37.         res =  res  + ",";
  38.         res =  res + getY();
  39.         res =  res  + ")>";
  40.         return res;
  41.  
  42.     }
  43.  
  44.     public boolean equals(Object other)
  45.     {
  46.         if(other instanceof Punt)
  47.         {
  48.             Punt that = (Punt) other;
  49.             return (this.getX().equals(that.getX()) && this.getY().equals(that.getY()));
  50.         }
  51.         else
  52.         {
  53.             return false;
  54.         }
  55.     }
  56.  
  57.     public double afstand() //distance
  58.     {
  59.         return Math.sqrt(getX()*getX()+getY()*getY());
  60.     }
  61.  
  62. }
and I'm trying to test Punt.java with TestPunt.java :


Expand|Select|Wrap|Line Numbers
  1. public class TestPunt
  2. {
  3.     public static void main(String []args)
  4.     {
  5.         Punt p1 = new Punt(1,2);
  6.  
  7.         System.out.println("p1.getX(): " + p1.getX());
  8.         System.out.println("p1.getY(): " + p1.getY());
  9.         System.out.println();
  10.  
  11.         System.out.println("p1.setX(4)");
  12.         p1.setX(4);
  13.         System.out.println("p1.getX(): " + p1.getX());
  14.         System.out.println();
  15.  
  16.         System.out.println("p1.setY(6)");         
  17.         p1.setY(6);
  18.         System.out.println("p1.getY(): " + p1.getY());
  19.         System.out.println("p1.toString(): "+p1.toString());
  20.  
  21.           Punt p2 = new Punt(2,4);
  22.  
  23.           System.out.println("p2.toString(): "+p2.toString());
  24.           System.out.println("p1.equals(p1): "+p1.equals(p1));
  25.           System.out.println("p1.equals(p2): "+p1.equals(p2));
  26.           System.out.println("p1.afstand(p2): "+p1.afstand(p2));
  27.      } 
  28. }
  29.  


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
Share this Question
Share on Google+
3 Replies


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

Dököll
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

Post your reply

Sign in to post your reply or Sign up for a free account.