All pastes #596676 Raw Edit

pee-m-dubba-ya

public java v1 · immutable
#596676 ·published 2007-06-30 03:33 UTC
rendered paste body
// loan amortization calculator Paul Brownimport java.util.Scanner;import java.text.DecimalFormat;public class LoanCalculator {   public static void main(String args[]) {      // Create an scanner for input      Scanner input = new Scanner(System.in);      // Enter loan amount      System.out.print("Enter loan amount, for example 25000.00: ");      double loanAmount = input.nextDouble();      //System.out.println("The Loan amount is $" + loanAmount);      // Enter yearly interest rate      System.out.print("Enter annual interest rate, for example 8.25: ");      double annualInterestRate = input.nextDouble();      //System.out.println("Annual Interest Rate is " + annualInterestRate +"%");      // Enter monthly payment      System.out.print("Enter monthly payment payment desired, for example 300.00: ");      double monthlyPayment = input.nextDouble();      //System.out.println("The Monthly Payment Amount is $" + monthlyPayment);      // Obtain monthly interest rate      double monthlyInterestRate = annualInterestRate / 1200;      double principle = loanAmount;      int month = 0;      DecimalFormat Decimal = new DecimalFormat(".00");      // formatting for top of table      System.out.println();      System.out.printf("%-6s%-10s%-8s%13s%13s", "Month", "Principle", "Payment", "To Principle", "To Interest");      System.out.println();      System.out.println("__________________________________________________");      // begin loop      while ( principle > monthlyPayment ) {         double monthlyInterest = (principle * monthlyInterestRate);         double toPrinciple = (monthlyPayment - monthlyInterest);         principle = (principle - toPrinciple);         month++;        System.out.printf("%-6s%-10s%-8s%13s%13s", (month), Decimal.format(principle), Decimal.format(monthlyPayment),              	      Decimal.format(toPrinciple), Decimal.format(monthlyInterest));        System.out.println();      }//end loop         // variables to calculate final payment         double finalMonthlyInterest = (principle * monthlyInterestRate);         double finalToPrinciple = (principle - finalMonthlyInterest);      // print final payment      System.out.printf("%-6s%-10s%-8s%13s%13s", (month + 1), Decimal.format(principle), Decimal.format(principle),                   		Decimal.format(finalToPrinciple), Decimal.format(finalMonthlyInterest));      System.out.println();   }}