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.
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
Re: completely stuck on a simple code
Please show us you have attempted to write a class and we can take it from there.
Re: completely stuck on a simple code
so far i made:
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.
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..
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;
}
}
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.