SHARE
TWEET

Carloan

RavenSH Jan 18th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* a program that calculates a monthly payment (carloan) */
  2.  
  3. public class CarLoan {
  4.     public static void main(String[] args) {
  5.  
  6.     int carLoan = 10000;
  7.   int loanLenght = 3; // 3 years
  8.   int interestRate = 5; // interest rate 5%  
  9.   int downPayment = 2000; //DP by a user for this car purchase
  10.    if (loanLenght <= 0 || interestRate <= 0) {
  11.      System.out.println("Error! You must take out a valid car loan.");
  12.    }
  13.     else if (downPayment >= carLoan){
  14.       System.out.println("The car can be paid in full.");
  15.     }
  16.     else {
  17.       int remainingBalance = carLoan - downPayment;
  18.       int months = loanLenght * 12;
  19.       int monthlyBalance = remainingBalance / months;
  20.       int interest = monthlyBalance * interestRate / 100;
  21.       int monthlyPayment = monthlyBalance + interest;
  22.      
  23. System.out.println(monthlyPayment);
  24.     }
  25.  
  26.      
  27.     }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top