• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please Explain  RSS feed

 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I sent this assignment into my professor and he replies saying that I "must call the two methods to do the problem." What does he mean. The program it's self is right. HERE IS WHAT HE SAYS: – Create method that gets yearly interest rate and calculates monthly rate
– Create a method called CalcInterest and pass the current value in account and monthly interest rate.  It should return how much is in the savings account . Thanks!

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:Create method that gets yearly interest rate and calculates monthly rate
Create a method called CalcInterest and pass the current value in account and monthly interest rate.  It should return how much is in the savings account .


So, where are the method (mentioned in bold)?  Aren't you supposed to implement them?

Henry
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method rate gets the yearly interest rate and calculates monthly rate. I also have the method calcinterest which prints it out. So what am I doing wrong?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:The method rate gets the yearly interest rate and calculates monthly rate. I also have the method calcinterest which prints it out. So what am I doing wrong?


The rate and calcinterest identifiers are *not* methods. They are both local variables. You do know the difference, right?  For example, in your code, main() is a static method -- ie., main() is a method.

Henry
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, and the local variable 'ca;cInterest' does not do what the name suggests, namely calculate the interest for that month. What does it do?
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I am actually so lost. I have no idea about methods
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay here is what I have. sorry for taking so long I am just not getting it and this is most likely wrong. Thanks!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The requirement ...

Junaid Mahmud wrote:– Create method that gets yearly interest rate and calculates monthly rate


Your code ...

Junaid Mahmud wrote:


Does your method do what is requested?

Henry
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's start with this:

Your instructor doesn't say so expressly, but I suspect they want you to return a value.  First let's name this method for what it does:

Next, we want to return a value: the monthly rate.  That's a type double, so let's declare the method as returning a double.

Next, we have to actually return a value.  We do this with the return keyword:

Now we have to use the return value.  In main(), you would have a line like this:

instead of


 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay so this is the updated version. So know am I done or would I have to fix the calculate method? Thanks!

 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still having issues with the method calculateInterest. Thanks!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the original requirement...

Junaid Mahmud wrote:
– Create a method called CalcInterest and pass the current value in account and monthly interest rate.  It should return how much is in the savings account .


Do your method have the required parameters? Do your method return the requested result? You need to get your code to do what is required.

Henry
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure what a parameter is. I don't believe we have covered that in class yet.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:I am not sure what a parameter is. I don't believe we have covered that in class yet.


Considering that your assignment explicitly specifies what your method parameters should be, and what it should return, it will be hard to do the assignment, if you never learned it.

I guess your two options are to ask your teacher, or review your notes (or alternatively, the tutorial provided above), to try to learn it on your own.

Henry
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh this is confusing
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it is not confusing.

You just need to step back and think, rather than type.

Consider the method you already have:


This is a method called yearlyToMonthly that passes the annural interest rate and returns the monthly interest rate.

The "passes" bit are the parameters to the method - the bit in brackets after the method name.  In this example you had one parameter: a double you called 'interest rate'
Return monthly interest rate:   You specify the return type of the method just before the method name.  In this case you have a "double"
You then use the keyword "return" in your method to set that as the result of calling the method.


Your instructions:
>Create a method called CalcInterest and pass the current value in account and monthly interest rate.  It should return how much is in the savings account

Given my explanation above, can you now write the declaration for this method?
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry but I am just not getting it.
 
salvin francis
Bartender
Posts: 1653
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:I'm sorry but I am just not getting it.

Hi, can you explain what is it that you are stuck at ?
The other posters have detailed the meaning of what a method is how you are supposed to define it. In the above example by knute, you can find a method which takes in One parameter and returns a value.

See:
DoYourOwnHomework
NotACodeMill

All the best with your assignment
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have literally tried thing that I came up and am still having problems. The output is the same for every month and I don't know why. Please Help

 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its been around 7 hours and I'm still stuck. What am I not understanding?
 
Sergiu Dobozi
Ranch Hand
Posts: 107
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:So I sent this assignment into my professor and he replies saying that I "must call the two methods to do the problem." What does he mean. The program it's self is right. HERE IS WHAT HE SAYS: –
– Create a method called CalcInterest and pass the current value in account and monthly interest rate.  It should return how much is in the savings account . Thanks!

You are confused because you haven't yet created a function called CalcInterest....I assume you need to put the current month and monthly interest rate as the two parameters into this function. So if you enter 10 (which is October) and you enter the interest rate, this method should return the total amount you have (maybe 10* interest + initial deposit).
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I created the method CalcInterest
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the updated version.

 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is so frustrating.
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I think I have figured it out. I would appreciate it if you could please read over my code and let me know if I have done what I am suppose to do which is
– Create method that gets yearly interest rate and calculates monthly rate
– Create a method called C alcInterest and pass the current value in account and monthly interest rate.  It should return how much is in the savings account .
– Create loop that executes the number of months and calls the method each month returning the new value in the account
– When loop is done print the amount in the account

Thanks for the help Guys, THANK YOU, but here is my code:



 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OOPS I sent the wrong code. Here is the following. Please let me know If I am doing this correctly as I should be :
– Create method that gets yearly interest rate and calculates monthly rate
– Create a method called C alcInterest and pass the current value in account and monthly interest rate.  It should return how much is in the savings account .
– Create loop that executes the number of months and calls the method each month returning the new value in the account
– When loop is done print the amount in the account

Thanks Again!

 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you certainly have shown a lot of effort!

See the method that calculates the monthly rate. You finally got there. Now, we do the same for the method 'calcInterest'.
For this, we need two input values: the value of the account at the beginning of the month, and the interest rate that is applicable during that month. So here goes:



or alternatively, and that is what you did so far in 'calci':



See? That works like the method that determines the interestrate per month.

I must correct an error I made in my earlier reply: the name 'calcInterest' is a bad name, since it suggests that it only calculates the interest gained. Bur according to your instructions, it must return the account at the end of the month. So a better name would have been something like: calcAccountEndOfMonth'.

Success!
 
Sergiu Dobozi
Ranch Hand
Posts: 107
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:But I created the method CalcInterest

You just created a variable called calcInterest.
CalcInterest method may look like this: public static double calcinterest(double amount, double months) {....}. This is the general form of a method.
For the code to work, move your yearlyToMonthly method inside your class and delete the calculateInterest method since it makes no sense and it's never used anyway.

You can't define methods inside main. Main() itself is a method, that's why it can't have other methods being defined inside of it.
You really should learn more about methods and parameters.
 
Sergiu Dobozi
Ranch Hand
Posts: 107
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw it wrong...now I realize that your methods are defined in the class and not in main.
 
Sergiu Dobozi
Ranch Hand
Posts: 107
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris' answer is way better, I just provided a quick solution, without the need of an extra method. It's much better to have a method to just call in main, then what you have now. So use Piet's answer on this one.
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep getting an output of zero now



 
Sergiu Dobozi
Ranch Hand
Posts: 107
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:I keep getting an output of zero now

Because you are not using your method, so you are not getting the calci you want. You are getting the calci you defined in main.
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this the correct way? Please let me know! Thanks!



 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junaid Mahmud wrote:Is this the correct way? Please let me know! Thanks!


No. You are still not calling your method.  What you did was copy the code from your method into your loop.

Henry
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I SO CLOSE to completing this program. The problem I am having is that it returns the output, but the output is off by a few. The problem is that the interest rate does not divide by 12 before returning the endValueOfAmount. Why is this! I could manually interesrate / 12 in the calculateInterest method, but that is what the yearlyToMonthly should be doing. Thanks


 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I GOT IT!!! Here's the proof and Thanks you guys so much!!!


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!