473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
3 1336
nimamc
2
No need to reply anymore, I already solved it :D Thanks anyways.
Oct 19 '08 #2
Dököll
2,364 Expert 2GB
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
JosAH
11,448 Expert 8TB
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

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

Similar topics

2
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to...
9
by: Peter Hansen | last post by:
The term "mock filesystem" refers to code allowing unit or acceptance tests to create, read and write, and manipulate in other ways "virtual" files, without any actual disk access. Everything is...
7
by: Marco | last post by:
I am looking for an open-source or free tool that parses a C header file (.h) for a module and creates a .c file with the functions stubbed out ( ideally with dummy returns for non-void). This will...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
1
by: listservs | last post by:
I have some unit testing code in one of my modules that appears to run without an error, but the unit test fails anyhow. Have a look at the output below -- the TestResult seems to have no errors...
58
by: nw | last post by:
Hi, I have been asked to teach a short course on testing in C++. Until now I have used my own testing classes (which from what I've seen seem similar to the boost unit testing classes)....
8
by: oh.i.love.spam | last post by:
I've been a procedural PHPer for a while now and I don't know why it has taken me so long to start the jump from procedural to OOP. I have a function that I would use for doing length...
20
by: earthwormgaz | last post by:
Hello, I'm after doing some C++ unit testing, I'm using CppUnit. I like the look of RudeMocks, but it doesn't work for Solaris/Sparc, so its no good to me sadly. So, I have class A, and it...
4
by: Emanuele D'Arrigo | last post by:
Hi everybody, I'm just having a go with Unit Testing for the first time and my feeling about it in short is: Neat! I'm a bit worried about the time it's taking me to develop the tests but...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.