Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Please enter the total cost of the car: ");
- int carCost = input.nextInt();
- System.out.print("Please enter the length of your loan in years: ");
- int loanLength = input.nextInt();
- System.out.print("Please enter your interest rate in %: ");
- int interestRate = input.nextInt();
- System.out.print("Please enter the down payment you will pay towards the cost of the car: ");
- int downPayment = input.nextInt();
- if (loanLength <=0 || interestRate <=0){
- System.out.println("Error! You must make a valid car loan (loan length and interest rate a positive number");
- }else if (downPayment >= carCost){
- System.out.println("No loan required, the car can be paid for in full");
- } else{
- int remainingBalance = carCost - downPayment;
- int months = loanLength * 12;
- int monthlyBalance = remainingBalance / months;
- int interest = (monthlyBalance * interestRate) / 100;
- int monthlyPayment = monthlyBalance + interest;
- System.out.println("Your total monthly payment is: " + monthlyPayment + " for " + months + " months");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement