View RSS Feed

Java Object

Passing Information to a Method or a Constructor

Rating: 1 votes, 1.00 average.
by , 04-26-2012 at 05:15 PM (972 Views)
Declaration for constructor or a method makes declared the type & number of the arguments for that constructor or method. For instance, given method computes the home loan monthly payments which depend upon the loan amount, loan length, interest rate or the loan’s future value.
Java Code:
public double computePayment(
                  double loanAmt,
                  double rate,
                  double futureValue,
                  int numPeriods) {
    double interest = rate / 100.0;
    double partial1 = Math.pow((1 + interest), 
                    - numPeriods);
    double denominator = (1 - partial1) / interest;
    double answer = (-loanAmt / denominator)
                    - ((futureValue * partial1) / denominator);
    return answer;
}
There are 4 parameters of this method: Number of periods, interest rate, loan amount and the future value. Last three are considered as floating point numbers which have double precision and 1st one is considered to be an integer. In method body, such parameters are being used and will take the argument values which have been passed in, at runtime.

Submit "Passing Information to a Method or a Constructor" to Facebook Submit "Passing Information to a Method or a Constructor" to Digg Submit "Passing Information to a Method or a Constructor" to del.icio.us Submit "Passing Information to a Method or a Constructor" to StumbleUpon Submit "Passing Information to a Method or a Constructor" to Google

Categories
Tutorial

Comments