Thursday, September 8, 2011

Java : EMI Calculator

Following program helps you to calculate the emi on daily/term basis and i have calculated for both.
I hope it will help you more to understand and if you have any inputs please inform me.

Java EMI Calculator - EMI.java

public class EMI {
      public static void main(String[] args) {
            double principal = 350000;
            double intrest = 6;// annual intrest.
            int years = 8;
            int months = 8 * 12;
            int days = 8 * 365;
            Date start = new GregorianCalendar(2011, 7, 26).getTime();
            Date end = new GregorianCalendar(2011, 9, 7).getTime();

            EMI emi = new EMI();
            System.out.println("Yearly EMI : "
                        + emi.regular(principal, intrest, years));
            System.out.println("Monthly EMI : "
                        + emi.regular(principal, intrest, months));
            System.out.println("Daily EMI : "
                        + emi.regular(principal, intrest, days));
            System.out.println("Daily EMI : "
                        + emi.daily(principal, intrest, start, end));
      }

      public double regular(double principal, double intrest, int terms) {
            double e = 0;
            double ti = intrest / (terms * 100); // term intrest
            e = principal * ti * Math.pow((1 + ti), terms)
                        / (Math.pow((1 + ti), terms) - 1);
            return e;
      }

      public double daily(double principal, double intrest, Date start, Date end) {
            Double days = (double) (end.getTime() - start.getTime())
                        / (1000 * 60 * 60 * 24);
            return regular(principal, intrest, days.intValue());
      }
}

No comments:

Post a Comment