# completely stuck on a simple code

• February 22nd, 2011, 09:35 AM
disp
completely stuck on a simple code
hey guys,

I'm having a problem figuring out how to make a good code for the following problem:

you have €100000 debt, the bank is asking 9% interest, and you want to pay the bank 15000 every year to make the debt 0.

now I need 2 different colums, 1 with the remaining debt after every year and 1 with the amount of interest you have to pay every year. how on earth do you make a working code for this problem.

I would really appreciate if someone could point me in the right direction.
• February 22nd, 2011, 10:25 AM
helloworld922
Re: completely stuck on a simple code
What have you tried so far?

If you're unsure where to get started, try reading The Java™ Tutorials
• February 22nd, 2011, 11:00 AM
JavaPF
Re: completely stuck on a simple code
Please show us you have attempted to write a class and we can take it from there.
• February 22nd, 2011, 01:35 PM
disp
Re: completely stuck on a simple code

Code Java:

```double x; int a; double r; int j;   r = 100000; a = 15000; x = 1.09;   for(j=1; j<=11; j++)   System.out.println(r*x-a);```

but that really doesnt do much for me :P except give the same anwser 11 times.
• February 22nd, 2011, 02:56 PM
JavaPF
Re: completely stuck on a simple code
If I were you, I would give the variables a decscriptive name so you know what you are working with.

The reason you are getting the same output 11 times is because the value printed never changes in the for loop..
• June 30th, 2011, 03:38 AM
munkybunky
Re: completely stuck on a simple code
Try this

Code Java:

```  package debt;   public class Debt {   public static void main(String[] args) { // TODO code application logic here   double debt = 100000; int payment = 15000; double interest = 1.09;   while (debt>0) { System.out.println("Debt "+(int)debt+" / Interest to pay "+(int)calcinterest(interest,debt)); debt=debt+calcinterest(interest,debt)-payment; } }   public static double calcinterest(double myinterest, double mydebt) { myinterest=(myinterest*mydebt)-mydebt; return myinterest; }   }```
• June 30th, 2011, 12:02 PM
dlorde
Re: completely stuck on a simple code
Assuming 'interest' is a percentage rate, your calcinterest method arithmetic is wrong (try working out a few examples on paper before trying to code it). Possibly using 'myInterest' for both the interest rate and the interest value has confused you. It certainly confused me.

Sensible naming is one of the most important and most neglected areas of coding.