Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## using integers

hey guys what's up?

I was trying to solve a problem that I met in my book Java how to program it's about compound interests.

```
public class Interests {

public static void main (String[] args) {

double p = 1000;
double rate = 0.05;
double amount;
for (int year = 1; year <= 10; year++){

amount = p * (Math.pow((1+rate),years));
System.out.printf("the amount for year %d is: %,20.2f", year, amount);
}//end for

}//end main

}//end class```

this was the original code. THE QUESTION IS: Modify the application to use only integers
to calculate the compound interest. [Hint: Treat all monetary amounts as integral numbers
of pennies. Then break the result into its dollars and cents portions by using the division and remainder
operations, respectively. Insert a period between the dollars and the cents portions.]

THE PROBLEM IS: it's ok to treat all monetary amounts as integral numbers of pennies then break the result into dollars and cents, but how can I convert the rate to an integer without losing data ?  Reply With Quote

3. ## Re: using integers

but how can I convert the rate to an integer without losing data ?
Can you post the program's output and show what the output should be?
5% = 5 / 100  Reply With Quote

4. ## Re: using integers

actually 5/100 cannot be an integer

that output should be the amount in pennies then I've to convert it using the reminder and the division operators to dollars and cents.
for example, if the p = 1000\$, the year = 2, the rate = 0.05 I should get 1102.5\$
what should I convert to: the p = 100000 pennies, the year = 2, I don't know what should the rate be but after calculating I should get an integer which should be 110250 ,then I've separate the dollars and the cents using the reminder and the division operator (I already know how to do this).  Reply With Quote

5. ## Re: using integers

Are you getting the desired answer now?
I don't see where you posted the output from the program and explain what is wrong with it and what you want the output to be.  Reply With Quote