• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calculating interest using java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm days into my highschool course and i recently got an assignment to calculate interest, and I'm just completely confused.
hw.PNG
[Thumbnail for hw.PNG]
This is basically what I have to do, and what i've somewhat have gotten so far :/
 
Adam no
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://gyazo.com/af75d33ddab82bdef4822889000e15a2

im so lost
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Adam,

welcome to the Ranch!

Don't panic, it is not very difficult.

Say you have an interestperunage of i, meaning that when you start with €1, you have (1 + i) euros after one year, (1 + i)^2 euros after two years, et cetera, (this is what is called "compund interest"), then what equation do you get when your initial € 1 has doubled after n years?

And do you know how to solve that equation, for n = 10, 20 and 30?

 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how they are expecting you to solve this programmatically. You could pick a rate and run it through a compound interest formula then IF it is more than double, reduce the rate and try again. IF it is less than double then increase the rate. Another way is to algebraically take the compound interest formula and solve for rate (this is a paper and pencil exercise), then implement the new formula in Java.

amount = principle * Math.pow(1 + rate/12, 12*years)

If you know that amount is two times the principle and you know the number of years, solve for rate.

Does this help at all?

 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Google: "compound interest solve for rate"
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enough time has passed so I don't think posting the answer should be an issue.

 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since OP did not respond anymore, I wouldn't have given a solution. But why are you using such a restrictive formula? Way back, we used to tease the students with interest based on a quarter year, but granted at the end of every fourth month, et cetera.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:. . . interest based on a quarter year, but granted at the end of every fourth month, et cetera.

So you worked in Iceland in 2008?
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm... if you earn 50,- per hour, and your salary is granted once every month, is your employer from Iceland?
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have forgotten what happened in Iceland in 2008.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:Since OP did not respond anymore, I wouldn't have given a solution.


I agree.  No complete solutions until the OP has posted their own.
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Piet Souris wrote:. . . interest based on a quarter year, but granted at the end of every fourth month, et cetera.

So you worked in Iceland in 2008?


Campbell Ritchie wrote:You have forgotten what happened in Iceland in 2008.


No, I haven't forgotten. And if the Icelanders did what you suggest, I doubt if they would have gone bust.

The idea is of course to go from an interest rate per quarter to an interest rate per a period of four months, and then calculate with periods of four months. That is why I said that Carey's formula is a bit limited, although the idea is the same: recalculate the (what we call 'apparent') interest per year to an interest per month, and calculate in month periods. So it is easier to simply have an interest per some period, and leave the definition of what that might be to the market, or to the loan supplier, or to the one who gives the assignment.

Interest calculus is an incredibly interesting subject, with a range of questions that resembles OCAJP with ease and that one can make as simple or as complicated as one likes. With all the todays valuation according to say Solvency II, we have that every period has its own "yearly" interest rate. So a period of one month has an interest rate of i1 per year, a period of two months has an interest rate of i2 per year, ad infinitum so to speak, making interest calculations even more interesting than they already were.

But I better stop now, before loosing the one person reading this too.
 
reply
    Bookmark Topic Watch Topic
  • New Topic