0
import java.io.*;
public class Amortization   { 
    public static void main (String[] args)throws IOException    {
        BufferedReader dataIn=new BufferedReader (new InputStreamReader (System.in));
        double loanamount=0.0, interestrate=0.0, numberofyears=0.0,amortization=0.0, a=(1+interestrate),b=numberofyears ; 
        String TextInput;
        System.out.print ("Input the loan amount: ") ; 
        TextInput=dataIn.readLine () ; 
        loanamount=Integer.parseInt (TextInput) ;
        TextInput=dataIn.readLine () ;
        System.out.print ("Input the interest rate: ") ; 
        TextInput=dataIn.readLine () ; 
        interestrate=Integer.parseInt (TextInput) ;
        TextInput=dataIn.readLine ()  ;
        System.out.print ("Input the number of years: ") ; 
        TextInput=dataIn.readLine () ; 
        numberofyears=Integer.parseInt (TextInput) ;
        TextInput=dataIn.readLine () ;
        amortization=loanamount*(interestrate*(1+interestrate)^numberofyears)/(1+interestrate)^numberofyears-1;
        System.out.println ("Monthly Amortization is: "+amortization) ; 
    }
}

I don't know how to put 'number of years' in exponent form. The user has to input loan amount, interest rate, and number of years.
I'm really new to this, so please bear with me. thanks guys!

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by dangari
0

import java.io.*;
public class Amortization {
public static void main (String[] args)throws IOException {
BufferedReader dataIn=new BufferedReader (new InputStreamReader (System.in));
double loanamount=0.0, interestrate=0.0, numberofyears=0.0,amortization=0.0, a=(1+interestrate),b=numberofyears ;
String TextInput;
System.out.print ("Input the loan amount: ") ;
TextInput=dataIn.readLine () ;
loanamount=Integer.parseInt (TextInput) ;
TextInput=dataIn.readLine () ;
System.out.print ("Input the interest rate: ") ;
TextInput=dataIn.readLine () ;
interestrate=Integer.parseInt (TextInput) ;
TextInput=dataIn.readLine () ;
System.out.print ("Input the number of years: ") ;
TextInput=dataIn.readLine () ;
numberofyears=Integer.parseInt (TextInput) ;
TextInput=dataIn.readLine () ;
amortization=loanamount*(interestrate*(1+interestrate)^numberofyears)/(1+interestrate)^numberofyears-1;
System.out.println ("Monthly Amortization is: "+amortization) ;
}
}

I don't know how to put 'number of years' in exponent form. The user has to input loan amount, interest rate, and number of years.
I'm really new to this, so please bear with me. thanks guys!

You can use java.lang.Math.pow((1+interestrate),numberofyears). This method returns type double.

preferrably, you can have a variable to store (1+interestrate) and another for (numberofyears-1) as below:

//Some of your code
double onePlusInterestRate =0.0, numberofyearsMinusOne=0.0;
onePlusInterestRate = 1+interestrate;
numberofyearsMinusOne = numberofyears-1;
//Some more of your code
amortization=loanamount*(interestrate*java.lang.Math.pow(onePlusInterestRate,numberofyears)/java.lang.Math.pow(onePlusInterestRate , numberofyearsMinusOne)

Hope this helps! (If it does just mark it as solved after my comments, Thanks)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.