Computer Science Canada Java Method Help |
Author: | samanthaxc [ Thu Mar 07, 2013 9:23 pm ] | ||||
Post subject: | Java Method Help | ||||
My program is supposed to allow the user to input a principle amount and rate, which it will calculate the the balance after it has been compounded for 10 years. It should display the balance at the end of every year. My problem is that when I try to return the amount to the main method, it won't work. some please help!
Mod Edit: Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
|
Author: | Zren [ Thu Mar 07, 2013 9:45 pm ] |
Post subject: | RE:Java Method Help |
Define exactly how it doesn't work. Does it show the wrong calculation? Does it not output at all? Does it cause an error? If it causes an error, what does the error message say? |
Author: | samanthaxc [ Thu Mar 07, 2013 9:47 pm ] |
Post subject: | Re: Java Method Help |
When I compile the program, it says the "return finalNumB" is incompatible and should be an 'int' |
Author: | Zren [ Thu Mar 07, 2013 9:52 pm ] | ||
Post subject: | RE:Java Method Help | ||
Well you're defining it as an int alright. However, you seem to be trying to return a value that hasn't been initialized (you don't set it to anything). You're probably going to run into all the years showing the same result. For this, I suggest you take a closer look at what variables you're using for what (and which you're not using at all). You also seem to be trying to format the value into a string inside that function that will be returning an integer. I suggest you make two functions, one to format the number into a humanly readable money string, and another to do your logic. Eg:
|
Author: | ishidon [ Thu Mar 07, 2013 10:13 pm ] | ||
Post subject: | Re: Java Method Help | ||
I believe what you're looking for is
|