Advertisement
MrDoyle

Car Loan Payment User Input

Aug 21st, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner input = new Scanner(System.in);
  8.         System.out.print("Please enter the total cost of the car: ");
  9.         int carCost = input.nextInt();
  10.         System.out.print("Please enter the length of your loan in years: ");
  11.         int loanLength = input.nextInt();
  12.         System.out.print("Please enter your interest rate in %: ");
  13.         int interestRate = input.nextInt();
  14.         System.out.print("Please enter the down payment you will pay towards the cost of the car: ");
  15.         int downPayment = input.nextInt();
  16.  
  17.         if (loanLength <=0 || interestRate <=0){
  18.             System.out.println("Error! You must make a valid car loan (loan length and interest rate a positive number");
  19.         }else if (downPayment >= carCost){
  20.             System.out.println("No loan required, the car can be paid for in full");
  21.         } else{
  22.             int remainingBalance = carCost - downPayment;
  23.             int months = loanLength * 12;
  24.             int monthlyBalance = remainingBalance / months;
  25.             int interest = (monthlyBalance * interestRate) / 100;
  26.             int monthlyPayment = monthlyBalance + interest;
  27.  
  28.             System.out.println("Your total monthly payment is: " + monthlyPayment + " for " + months + " months");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement