Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. /*
  2. AUTHOR: KODY SNYDER
  3. DATE: 2/23/2017
  4. COURSE: CSCI 111
  5. TITLE: CAR LOAN PAYMENT CALCULATOR
  6.  */
  7. package carpayment;
  8.  
  9. import java.util.*;
  10.  
  11. public class CarPayment {
  12.  
  13.  
  14.     public static void main(String[] args) {
  15.         Scanner kb = new Scanner(System.in);
  16.        
  17.         // Variable declarations
  18.         String name;
  19.         double loan;
  20.         double monthly = 0;
  21.         double rate;
  22.         double months;
  23.         double payment = 0;
  24.    
  25.         // Obtain user input for Loan, Interest Rate, and Month Terms
  26.         System.out.println("What is your name?");
  27.         name = kb.nextLine();
  28.        
  29.         System.out.println("Enter loan amount: ");
  30.         loan = kb.nextDouble();
  31.        
  32.         System.out.println("Enter annual interest rate: ");
  33.         rate = kb.nextDouble();
  34.        
  35.         System.out.print("Enter amount of months on loan term: ");
  36.         months = kb.nextDouble();
  37.        
  38.         monthlyRate(rate, monthly); // Call MonthlyRate
  39.         monthly = monthlyRate(rate, monthly); // Assign Monthly the value
  40.        
  41.         monthlyPayment(rate, months, loan, monthly, payment); // call MonthlyPayment
  42.         payment = monthlyPayment(rate, months, loan,monthly, payment); // Assign Payment the value
  43.        
  44.         calculationOutput(loan, rate, months, monthly, payment); // call CalculationOutput, outputting information
  45.        
  46.         kb.close(); // Close Scanner
  47.        
  48.     }
  49.    
  50.     // Method to find Monthly Interest Rate
  51.     public static double monthlyRate(double rate, double monthly) {
  52.         monthly = (rate / 12);
  53.         return monthly;
  54.     }
  55.    
  56.     public static double monthlyPayment(double rate, double months, double monthly, double loan, double payment) {
  57.         payment = ((monthly*Math.pow(1 + monthly, months))/(Math.pow(1 + monthly, months) -1));
  58.         return payment;
  59.     }
  60.    
  61.     public static void calculationOutput(double loan, double rate, double monthly, double months, double payment) {
  62.        
  63.         System.out.println("Car Loan Monthly Payment Calculator");
  64.         System.out.printf("%16s%16s%16s%16s%16s%n", "Amount Borrowed", "Annual Rate",
  65.                  "Monthly Rate", "Length of Loan", "Monthly Payment" );
  66.         System.out.printf("%16.0f%16.0f%16.0f%16.0f%16.0f%n", loan, rate, monthly,
  67.         months, payment);
  68.                
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement