5 Replies - 1365 Views - Last Post: 06 September 2010 - 05:29 PM Rate Topic: -----

#1 Guest_Tim*


Reputation:

Simple problem but cannot find the answer

Posted 05 September 2010 - 03:06 PM

the problem with this code is that it will not compile due to

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
  symbol:   constructor eTOx(double)
  location: class javaapplication7.eTOx
        at javaapplication7.Main.main(Main.java:16)


can anyone help out

public class eTOx{


    public static void main(String[] args) {


        System.out.println(eTOx(5));
    }

    public static float eTOx(float  x){

        float repeat= 1+x;
         float  n=2;
         float  answer=0;
        float  newAns=0;

        for(int i=0;i<100;i++){


          newAns=newAns+((float) Math.pow(x, n))/fact(n);

            n++;

        }
answer=repeat+newAns;

        return answer;
    }

 public static float fact(float num) {


	if (num <= 1) {
	    return 1;
	}

	else {
	    return num * fact(num-1);
	}
    }


}




Please use code tags in the future -> :code:

-Locke

Is This A Good Question/Topic? 0

Replies To: Simple problem but cannot find the answer

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Simple problem but cannot find the answer

Posted 05 September 2010 - 03:09 PM

I believe the problem is that you are using a function with the same name as your class (public static float eTOx(float x){). The class is called eTOx, so does the function. I'm sure thre's a conflict between them. Try renaming that function, or the class.

This post has been edited by sarmanu: 05 September 2010 - 03:11 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_Tim*


Reputation:

Re: Simple problem but cannot find the answer

Posted 05 September 2010 - 03:13 PM

I had changed them and there was no difference, still not compiling...
Was This Post Helpful? 0

#4 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Simple problem but cannot find the answer

Posted 05 September 2010 - 03:25 PM

I've changed the name of the class, and everything worked (compiling part). So double check everything. I'm no Java expert so that's about everything I can tell you about compiling part. What I can surely tell you about logic part is that the program will not provide good results, mostly because newAns=newAns+((float) Math.pow(x, n))/fact(n);, part fact(n). What happens when n is like 50? Does factorial(50) fit in a float? Definitely not. I believe you can use BigInteger class to handle very big numbers.

This post has been edited by sarmanu: 05 September 2010 - 03:29 PM

Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: Simple problem but cannot find the answer

Posted 05 September 2010 - 04:01 PM

@Tim: Post your revised code. Also, in Java, it is better practice to use doubles as they have higher precision and range of values.
Was This Post Helpful? 0
  • +
  • -

#6 k1ngcor3y  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 69
  • Joined: 27-August 10

Re: Simple problem but cannot find the answer

Posted 06 September 2010 - 05:29 PM

Nevermind

This post has been edited by k1ngcor3y: 06 September 2010 - 05:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1