Skip to content

Instantly share code, notes, and snippets.

@sunnyeyez123
Created November 9, 2017 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnyeyez123/25d61140a33602b0ff4996eb73019613 to your computer and use it in GitHub Desktop.
Save sunnyeyez123/25d61140a33602b0ff4996eb73019613 to your computer and use it in GitHub Desktop.
A program that will calculate the monthly car payment a user should expect to make after taking out a car loan
/*a program that will calculate the monthly car payment a user should expect to make after taking out a car loan*/
public class CarLoan {
public static void main(String[] args) {
int carLoan = 10000;
int loanLength = 3;
int interestRate = 5;
int downPayment = 2000;
if (loanLength <= 0 || interestRate <= 0 ){
System.out.println("Error! You must take out a valid car loan.");
}else if(downPayment > carLoan){
System.out.println("The car can be paid in full.");
}else{
int remainingBalance = carLoan - downPayment;
int months = loanLength *12;
int monthlyBalance = remainingBalance/months;
int interest = (monthlyBalance*interestRate)/100;
int monthlyPayment = monthlyBalance + interest;
System.out.println(monthlyPayment);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment