• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to print a variable returned from some other method?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..










Thanks...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Store it to a local variable, or use the method call in the print statement.
 
akash negi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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..

THANKS!!
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the method call where the local variable is (in the print statement).
 
Ranch Hand
Posts: 95
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic