# Thread: Problem with Calculation ....

1. Member
Join Date
Jul 2007
Posts
2
Rep Power
0

## Problem with Calculation ....

i need to calculate :

interest earned = invesment value (current) * (interest rate / 100)
invesment value (new) = invesment value (current) + interest earned

how do i write in a java program ?

is it ,
Java Code:
```import java.util.scanner;
public class invesment
{
public static void main (String [] args)
{

double intEarned = a;
double inteValue = b;
double newInves = c;

Scanner keyboard = new Scanner(System.in);

// this where we input the value
b = keyboard.nextDouble();

int i = 0;
while (i < 5 )
{
a = b * (10/100)
c = b + a

i = i + 1;
}

and so on.```
my result must be like this :

year interest Earned Investment Value
---- --------------- -----------------
1 \$10.00 \$110.00
2 \$11.00 \$121.00
3 \$12.10 \$133.10
4 \$13.31 \$146.41
5 \$14.64 \$161.05

* how do i loop it ?
* is my calculation is correct ?

Thanks!
Last edited by danny000; 07-30-2007 at 01:41 PM.

2. I'll be amazed if you are still looking for the answer to this problem. Hope this helps.

Java Code:
```import java.util.*;

public class investment {

public static void main(String[] args) {

double intEarned;// just use these for your variables, no a/b/c needed
double inteValue;//you dont need newInves, just change inteValue.
double interestRate = 10;// interest rate as variable so it is easier to
// change
int years = 5;// make the years an easily changed variable
Scanner keyboard = new Scanner(System.in);

// this where we input the value
inteValue = keyboard.nextDouble();
System.out.println("year interest Earned Investment Value");
System.out.println("---- --------------- -----------------");
for (int i = 0; i < years; i++) {// for loop controls the counter for you so you dont have to worry about it
intEarned = inteValue * (interestRate / 100);
inteValue = inteValue + intEarned;
System.out.print((i + 1));
System.out.printf(" \$%.2f", intEarned);// formated output for 2 decimal places
System.out.printf(" \$%.2f%n", inteValue);
}

}
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•