posted 7 years ago
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:
package assignment06;
/* Design a SavingsAccount class that stores a savings account's annual
* interest and balance.
*
*
}
and here is my TestAccount that i run from:
here's my work:
package assignment06;
/* Design a SavingsAccount class that stores a savings account's annual
* interest and balance.
*
*
}
and here is my TestAccount that i run from:
dannygirl sylvest
Greenhorn
Posts: 9
posted 7 years ago
Can you give an example of a user input, and the values that you are expecting ?
[My Blog]
All roads lead to JavaRanch
posted 7 years ago
interest is 0.0, and will always be. Also, you are not using the returned value of calculateInterest.
interest is 0.0, and will always be. Also, you are not using the returned value of calculateInterest.
[My Blog]
All roads lead to JavaRanch
posted 7 years ago
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.
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.
Everyday in every way, we get a little better.
Bobby Smallman
Ranch Hand
Posts: 107
posted 7 years ago
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 :-)
Everyday in every way, we get a little better.
dannygirl sylvest
Greenhorn
Posts: 9
Bobby Smallman
Ranch Hand
Posts: 107
dannygirl sylvest
Greenhorn
Posts: 9
posted 7 years ago
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!
// 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!
Bobby Smallman
Ranch Hand
Posts: 107
posted 7 years ago
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.
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.
Everyday in every way, we get a little better.
dannygirl sylvest
Greenhorn
Posts: 9
posted 7 years ago
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.
Ok I did this :
public double MonthlyInterestRate( double annualrate)
{
return annualrate / 12 ;
}
and then this:
// Calculate interest from balance.
interest = balance *= account.MonthlyInterestRate(interestRate);
It gave me the correct interest. But now it didn't add it to my total balance. I'ts still 1, 000. What would cause that when it was working great a minute ago?
Ok I did this :
public double MonthlyInterestRate( double annualrate)
{
return annualrate / 12 ;
}
and then this:
// Calculate interest from balance.
interest = balance *= account.MonthlyInterestRate(interestRate);
It gave me the correct interest. But now it didn't add it to my total balance. I'ts still 1, 000. What would cause that when it was working great a minute ago?
Bobby Smallman
Ranch Hand
Posts: 107
dannygirl sylvest
Greenhorn
Posts: 9
Bobby Smallman
Ranch Hand
Posts: 107

If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
|