Cant Solve this Java Error

Thread Solved

Join Date: Oct 2009
Posts: 3
Reputation: prelyptica is an unknown quantity at this point 
Solved Threads: 0
prelyptica prelyptica is offline Offline
Newbie Poster

Cant Solve this Java Error

 
0
  #1
28 Days Ago
I an trying to write a few java classes, which I wrote successfully, but when I am tryin to test it I get some weird errors and I cant figure out why, so i'd be very grateful for your expertise.

The code for the GCD class is:
  1.  
  2. public class GCD {
  3. public static long gcd(long x, long y) {
  4. while (y != 0) {
  5. long r = x % y;
  6. x = y; y = r;
  7. }
  8. return x;
  9. }
  10. }
This compiles without any problems.


The code to test the GCD class is :
  1.  
  2. import java.util.*;
  3. public class GCDTest {
  4. public static void main(String[] args) {
  5. long x = (long)(Math.random()*199)+1;
  6. long y = (long)(Math.random()*199)+1;
  7. GCD value = new GCD (x,y);
  8. System.out.println("gcd(" + x + ", " + y + ") = " + value);
  9. }
  10. }
When I compile it gives me the following error:

GCDTest.java:9: cannot find symbol
symbol : constructor GCD(long,long)
location: class GCD
GCD value = new GCD (x,y);
^

Here is the class for Random Prime Number Generation:
  1. import java.util.*;
  2. public class RandomPrimeNos {
  3. public static long RandomPrimeNos () {
  4. long p = (long)(Math.random()*199)+1;
  5. boolean pIsPrime = false;
  6. long i=2;
  7. while(i<=(p-1) && pIsPrime==false){
  8. if(p%i==0){
  9. pIsPrime=false;
  10. p = (long)(Math.random()*199)+1;
  11. i = 2;
  12. } else {
  13. i++;
  14. }
  15. if(i>=(p-1)) {
  16. pIsPrime=true;
  17. }
  18. }
  19. return (p);
  20. }
  21. }
When I compile it, it works fine.

The code to test the Random Prime Number Generation class is :
  1. import java.util.*;
  2. public class RandomPrimeTest {
  3. public static void main(String[] args) {
  4. RandomPrimeNos randNum = new RandomPrimeNos ();
  5. System.out.println(randNum);
  6. }
  7. }
It compile fine. but give me the following output instead of giving me a random prime number: RandomPrimeNos@c3c749


I hope someone can help me and tell me what I am doing wrong.
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #2
28 Days Ago
public class GCD have a static method gdc. Then you do not need to create new instance of this class .
simply use long val = GDC.gdc(l1,l2);
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: prelyptica is an unknown quantity at this point 
Solved Threads: 0
prelyptica prelyptica is offline Offline
Newbie Poster
 
0
  #3
28 Days Ago
so ur saying der is an already built in function that does gcd ? and i can use it by just calling it ?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: prelyptica is an unknown quantity at this point 
Solved Threads: 0
prelyptica prelyptica is offline Offline
Newbie Poster
 
0
  #4
28 Days Ago
Originally Posted by prelyptica View Post
so ur saying der is an already built in function that does gcd ? and i can use it by just calling it ?
Yay I fixed it Thank u sooo much!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 91
Reputation: thines01 is an unknown quantity at this point 
Solved Threads: 8
thines01 thines01 is offline Offline
Junior Poster in Training
 
0
  #5
28 Days Ago
Simply, it's failing because you do not have a constructor that takes two longs.
Reply With Quote Quick reply to this message  
Reply

Tags
class, error, java

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC