TizzyT

CarLoans -TizzyT

Feb 29th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. package carloans;
  2. import java.util.*;
  3. public class CarLoans {
  4.     public static void main(String[] args) {
  5.         // Scanner object for user inputs
  6.         Scanner inputs;
  7.         inputs = new Scanner(System.in);
  8.         // Asks user for amount of loan
  9.         System.out.println("Please input Loan Amount in Dollars (ex: 4500.00):");
  10.         double LoanAmount = inputs.nextDouble();
  11.         // Asks user for amount of interest rate
  12.         System.out.println("Please input Interest Rate in Decimals (ex: 7.5% = 0.075):");
  13.         double Rate = inputs.nextDouble();
  14.         // Asks user for number of months
  15.         System.out.println("Please input Loan Duration in Months:");
  16.         int Months = (int)inputs.nextDouble();
  17.         // Closes the scanner object
  18.         inputs.close();
  19.         // Stores calculations made
  20.         double MonthlyInt = MonthlyInterest(Rate);
  21.         double MonthlyPayment = MonthlyPay(LoanAmount, MonthlyInt, Months);
  22.         // Prints loan information
  23.         PrintInfo(LoanAmount, Rate, Months, MonthlyPayment);
  24.     }
  25.     // Calculates the Monthly interest given the anual interest
  26.     public static double MonthlyInterest(double AnnualInterest) {
  27.         return AnnualInterest / 12;
  28.     }
  29.     // Calculates the Monthly Payment given amount, monthly interest, and number of months
  30.     public static double MonthlyPay(double Amount, double MonthlyInterest, int Months) {
  31.         return (MonthlyInterest * Amount) / (1 - (Math.pow(1 + MonthlyInterest, Months * -1)));
  32.     }
  33.     // Displays the loan information including the calculated values
  34.     public static void PrintInfo(double Borrowed, double Annual, int Months, double MonthlyPay) {
  35.         System.out.printf("Amount Borrowed   Annual Interest Rate   Length of Loan  Monthly Payment\n" +
  36.                           "%15.2f%23.3f%17d%17.2f", Borrowed, Annual, Months, MonthlyPay);
  37.     }
  38. }
Add Comment
Please, Sign In to add comment