waltermilner

Untitled

Apr 26th, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class Test {
  2.  
  3.   public static void main(String[] args) {
  4.     // all amounts of money in cents or pennies
  5.     int p = 10000; // initial loan = $100.00
  6.     int a = 2000; //monthly repayment = $20.00
  7.     double i = 2.5; // monthly interest per cent
  8.     int interest; // due each month
  9.     int cumulativeInterest = 0;
  10.     int unpaid = p;
  11.     int payment;
  12.     int monthCount = 0;
  13.     while (unpaid > 0) {
  14.  
  15.       interest = (int) (unpaid * i / 100.0); // truncates cents
  16.  
  17.       cumulativeInterest += interest;
  18.       unpaid += interest;
  19.       payment = a;
  20.  
  21.       if (unpaid > payment) {// normal payment
  22.         unpaid -= payment;
  23.       } else { // final payment
  24.         payment = unpaid;
  25.         unpaid = 0;
  26.       }
  27.       monthCount++;
  28.       System.out.println("Interest = " + interest / 100.0 + " Cumulative interest = " + cumulativeInterest / 100.0 + " Payment = " + payment / 100.0 + " Outstanding = " + unpaid / 100.0);
  29.     }
  30.     System.out.println("Paid off in " + monthCount+" months");
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment