import java.util.*;
  public class sSfive  {
  public static void main ( String[] args )  {
    Scanner nix = new Scanner ( System.in );

      System.out.print ( "Enter interest rate: " );
	float inInt = nix.nextFloat;
      System.out.println ( "" );
      System.out.print ( "Enter number of year: " );
	int inYear = nix.nextInt;
      System.out.println ( "" );
      System.out.print ( "Enter loan amount: " );
	int inLoan = nix.nextInt;
      System.out.println ( "" );

	float mPay = ( inLoan*inInt ) / ( 1 - ( 1 / ( 1+inInt )*Math.pow( inYear*12 ) ) );
      System.out.printf ( "Monthly payment = " + mPay" );

  }
}

program that computes loan payments. The program lets the user enter the interest rate, number of years, and loan amount, and displays the monthly and total payments. The formula to compute the monthly payments is as follows:

montlyPayment=(loanAmount X monthlyInterestRate)/(1-(1/(1+monthlyInterestRate)numberOfYearsX12))

i need help with this one, i don't know how to use math class

Recommended Answers

All 2 Replies

in lines 7,10, 13,
the methods nextInt(), nextFloat() are called. the () is missing. The code should be:
double inInt = nix.nextFloat();
...
int inYear = nix.nextInt();
...
int inLoan = nix.nextInt();
You are using the static method of pow of the Math class.
If your fomula is correct, the code for the calculation in line 16 should be:

double mPay = ( inLoan*inInt ) / ( 1 - ( 1 / Math.pow( ( 1+inInt ),inYear*12 ) ) );

For example, you want to get 2.0^4.0, then the result d in the type of double is:
double a=2.0, b=4.0;
double d = Math.pow(a,b);

i don't know how to use math class

Write a simple program that calls the various methods of the Math class and prints out the results to see what they do.

When debugging your code, break up the long expressions into single simple expressions and print out the intermediate results to verify your math is correct. With the long expressions shown here either it works or it doesn't and there are few clues on where the problem is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.