for loop - Calculating interest rate in java -


i'm making method supposed calculate interest rate of amount on period of years (these values defined in parameters). code have far:

    public void balance(int amount, double rate, int year){     double yearlyrate = amount * rate;     double totalamount;       system.out.print(amount + " :- " + " grows interest rate of " + rate);      (int = 0; <= year; i++ ){            ( int j = amount; j)               totalamount = amount + yearlyrate;               system.out.println(i + "   " + totalamount);     }  } 

i on way make nested for-loop can see there there missing code. here ran in trouble. first for-loop runs through years , other supposed calculate total amount. clear years defined in variable "int year" let's 7, program supposed calculate growth of amount each year so:

year1 totalamount  year2 totalamount  year3 totalamount  , on..... 

the main method looks this:

public void exerciceg(prog1 prog1) {     system.out.println("test of: balance");     prog1.balance(1000, 0.04, 7); } 

i appreciate can get!

here's 1 change make, there may lot else mentioned in comment:

totalamount = totalamount + amount + yearlyrate; 

which written:

totalamount += amount + yearlyrate; 

you might want drop for j loop since doesn't is.

edit

this guess since i'm not sure know objective is, how about:

public static void balance(int amount, double rate, int year){    double yearlyinterestpaid ;   double totalamount = amount;     system.out.println(amount + " :- " + " grows interest rate of " + rate);    (int = 0; <= year; i++ ){      yearlyinterestpaid = totalamount * rate;     totalamount += yearlyinterestpaid;     system.out.println(i + "   " + totalamount);   } } 

this output:

test of: balance 1000 :-  grows interest rate of 0.04 0   1040.0 1   1081.6 2   1124.8639999999998 3   1169.85856 4   1216.6529024 5   1265.319018496 6   1315.93177923584 7   1368.5690504052736 

it's reasonable assume objective.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -