How to print a variable returned from some other method?
akash negi
Greenhorn
Joined: Feb 24, 2010
Posts: 27
posted
0
I actually missed one lecture in which our professor talked about methods. and I have an assignment to do, in which we can not ask for input or print anything in the methods but we can print and ask for input in the main program.
I tried to learn methods and their implementation in java on my own through various online sources, but I am not aware of how to print the new variable returned from some other method.
Below is my code. Right now, it gives me an error saying that "finalrate" could not be found.
The assigned problem is:
Create a module called Finance.java. Inside this module, write methods to perform the following tasks. You will have to write an appropriate method signature and also implement the method by writing code.
Compute Annual Percentage Yield (APY): Given an annual interest rate (on some kind of deposit account) and the number of times per year that interest compounds, compute the corresponding APY. (formula)
Compute monthly loan payment: Given a loan amount (principal), an annual interest rate, and the duration of the loan (in years), compute the monthly payment the borrower will have to pay. (formula)
These methods should not use the IO module at all. Declare arguments to each method to obtain inputs. Use the "return" statement to provide output.
Construct a set of test cases for your Finance methods, and write a driver program called FinanceDriver that executes your test cases by calling each method with the appropriate inputs. Write the expected output of each test case in a comment in your driver.
I am just working on the APY part of the problem right now..
Store it to a local variable, or use the method call in the print statement.
akash negi
Greenhorn
Joined: Feb 24, 2010
Posts: 27
posted
0
David Newton wrote:Store it to a local variable, or use the method call in the print statement.
A friend of mine suggested me to store in a local variable and then print and it works. But how would you do a "method call" in the print statement? Our professor hasn't taught us how to do that.
I don't think we are allowed to use it, but it would be interesting when you don't want to create any new variable..