You are viewing our Forum Archives. To view or take place in current topics click here.
Java Program Help
Posted:

Java Program Help Posted:

xSensationz
  • TTG Natural
Status: Offline
Joined: Aug 11, 201014Year Member
Posts: 901
Reputation Power: 37
Status: Offline
Joined: Aug 11, 201014Year Member
Posts: 901
Reputation Power: 37
I am having a problem getting the correct answer to display. Is there any other way I could write this last part?

[ Register or Signin to view external links. ]
#2. Posted:
Kyle93
  • Retired Staff
Status: Offline
Joined: Jun 25, 201014Year Member
Posts: 4,078
Reputation Power: 2628
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Status: Offline
Joined: Jun 25, 201014Year Member
Posts: 4,078
Reputation Power: 2628
Motto: https://www.thetechgame.com/Forums/t=7804 333/vote-for-tune-of-the-week-friday-nigh ts-lockdown-dj-sets.html
Could you post all of your actual code in the post with the "code" tags. Then I can take an actual look for you.

Provisionally tho, what are you trying to do, calculate the interest? How is that done?

Doing what you did, you get the answer you should get.

2000 * 2.71828 = 5436.56
0.07 * 20 = 1.4
5439.56^1.4 = 169741.9863757396330986077861333


Meaning your logic is wrong, or you are using the wrong function.

As Math.pow(x,y); does

Returns the value of the first argument raised to the power of the second argument.


So, you are getting the answer you should get in the way the program works. Tell us how you are supposed to be actually getting the value and I'll do a solution.
#3. Posted:
Imp
  • Shoutbox Hero
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
You have not quite got the continuous compound interest formula correct.

Future Principal = Principal * (1 + NominalRate) ^ time

So in code you will have to do this.

temp4 = Math.pow(2.71828,rate);
temp5 = Math.pow(temp4,time);
answer = principal * temp5;

I believe in your example this should give.

temp4 = Math.pow(2.71828,0.07); = 1.0725081307
temp5 = Math.pow(1.0725081307,20); = 4.0551961480...
answer = 2000 * 4.0551961480; = 8110.3922960173...

Which is what you are looking for
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.