
-----------------------------------
mendem03
Wed Jun 02, 2010 12:15 pm

array help
-----------------------------------
 
import java.io.*;
class like
{
	public static void main(String 

How do i get the arry value into the loop when im multiplying. interestRate is the array, i want to multiply with the amount.
I really need help with this.

-----------------------------------
DemonWasp
Wed Jun 02, 2010 1:31 pm

RE:array help
-----------------------------------
Perhaps you should index it with interestPeriod, instead of a hard-coded number (1,2,3) like you have above. For example:


System.out.println( "Your interest payment is $" + (interestPayment=amount*interestRate

-----------------------------------
mendem03
Wed Jun 02, 2010 3:35 pm

Re: array help
-----------------------------------
i made an adjustment and i need help with this one
 
import java.io.*;
class lkj
{
		public static void main(String 
I gave interestRate values to the user and depending on want they pick they will get the value but now im trying to use that value for a calculation but i dont know how to get it to work. Im trying to do the calculation in the loop.
Can someone try the program and help me please.

-----------------------------------
yoursecretninja
Thu Jun 03, 2010 4:43 pm

Re: array help
-----------------------------------
I just peaked at the stuff pertaining to the interest rate. Why are you using an array for interest rates?

You ask the user to choose an amount of money to borrow. The entered amount of money is compared against three ranges of values.

For amount within range A you set the value of interestRate at index 0.
For amount within range B you set the value of interestRate at index 1.
For amount within range C you set the value of interestRate at index 2.

moving along to the part just before you perform your calculations in that for loop...

You create an integer called interestRate2 and assign it the value of one.

You then assign the value of InterestRate at index interestRate2 to the value of interestRate2... do you see what you did there?

You then calculate the interest payment as amount * ((the value of interestRate at index interestRate2 / 100) + 1). 

Does following this logic in plain english, rather than looking at code, help you see why you'll get the wrong answer every time you run the program (assuming the program actually compiles and runs)? Do you see what you are doing when you operate on that array? Do you see how this problem would be much easier if you used an integer to hold the interest rate instead of an array? I hope this is helpful... I'd like to help you understand how to fix this rather than just fixing it for you as this looks like it might be a homework assignment.
