Java program to calcuate EMI

Program:

[java]
package com.javadomain.flipkart.in;
public class EMI {
public static void main(String[] args) {

String amount ="200000";
String inter = "12";
String month = "84";

// double loanAmount = 200000;
// int rateOfInterest = 12;
// int numberOfMonths = 84;

double loanAmount = Double.parseDouble(amount);
int rateOfInterest = Integer.parseInt(inter);
int numberOfMonths = Integer.parseInt(month);

double temp = 1200; //100*numberofmonths(12))
double interestPerMonth = rateOfInterest/temp;
//System.out.println(interestPerMonth);

double onePlusInterestPerMonth = 1 + interestPerMonth;
//System.out.println(onePlusInterestPerMonth);

double powerOfOnePlusInterestPerMonth = Math.pow(onePlusInterestPerMonth,numberOfMonths);
//System.out.println(powerOfOnePlusInterestPerMonth);

double powerofOnePlusInterestPerMonthMinusOne = powerOfOnePlusInterestPerMonth-1;
//System.out.println(powerofOnePlusInterestPerMonthMinusOne);

double divides = powerOfOnePlusInterestPerMonth/powerofOnePlusInterestPerMonthMinusOne;

double principleMultiplyInterestPerMonth = loanAmount * interestPerMonth;
//System.out.println(principleMultiplyInterestPerMonth);

double totalEmi = principleMultiplyInterestPerMonth*divides;
System.out.println("EMI per month (Exact) : " + totalEmi);

double finalValue = Math.round( totalEmi * 100.0 ) / 100.0;

System.out.println("EMI per month (Rounded) : " + finalValue);
}
}
[/java]

Output:

EMI per month (Exact) : 3530.546559414762
EMI per month (Rounded) : 3530.55

 

 

Thanks for reading this post………….!!!

Leave a Reply