I created a SavingsAccount class that's suppose to calculate a monthly interest rate (based off whatever the annual is inputed by user) and then add it to the balance and to a totalInterest accumulator. For some reason my formula keeps dividing instead of multiplying and i can't figure out why? Any ideas?
here's my work:
/* Design a SavingsAccount class that stores a savings account's annual
* interest and balance.
the problem i'm having may be user error since it has to do more with how the interest was calculated. I just can't seem to find a way to fix it. I've been at this for 3 days trying to fix it, but keep it how my teacher wanted it to be. Maybe i'm using a constructor wrong?
Looks like you forgot to actually change the interest..... looks to me that from like 69 onwards you are dealing with your default interest of 0...
Without digging into it too much, I think you meant to first calculate the monthly interest rate, THEN give that rate to your line 69 to get the amount of interest earned....then take that and add it to your balance etc.
Also, not that it is causing your errors, but since you are turning this in for a project, go back through and take a look at your variable names etc. Couple oddly named ones, some are capitalized, some are missing CamelCasing etc, might as well get it right if you are getting graded :-)
ok i see what you guys are saying. So i guess i'm having trouble getting the interest rate the correct value? should i say :
// Calculate interest from balance.
Balance *= ( and this is where i get a little confused) can you multiply a class method here? Or do i have to well darn i'm confused lol. I know what needs to be done but i can't figure out how to go about doing it no matter how much i stare at that darn textbook!
It looks like you have the method in place to calculate the monthly interest rate, but you simply aren't using it. You also have a method for calculating the actual interest gained in the month, but you are passing it firstly your "interest" variable instead of your newly calculated monthly interest rate. So you need a variable for monthlyInterestRate which you will calculate by dividing your inputed annual interest rate (however you like, you can use your method you already made) and then when you go to call your calculateInterest, call it like
In your original code you were never actually modifying your "interest" variable, and you never fully calculated your monthlyInterestRate.
Seems like you may have simply gotten confused about what your variables were because you have the functional parts there....your "interest" is really more like "interestEarned" if I am understanding it correctly.
I was trying to call the method MonthlyInterestRate(interestRate); but for some reason my teacher made it private instead of public so it brings up an error. I don't understand why he did that but i think i'm going to switch it to private and see how that goes.
Like I said above, that "balance" there which you are adding it to is not your "account.balance" it is referring to your balance variable in your TestAccount class. Use your "account.setBalance()" method.