Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* a program that calculates a monthly payment (carloan) */
- public class CarLoan {
- public static void main(String[] args) {
- int carLoan = 10000;
- int loanLenght = 3; // 3 years
- int interestRate = 5; // interest rate 5%
- int downPayment = 2000; //DP by a user for this car purchase
- if (loanLenght <= 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 = loanLenght * 12;
- int monthlyBalance = remainingBalance / months;
- int interest = monthlyBalance * interestRate / 100;
- int monthlyPayment = monthlyBalance + interest;
- System.out.println(monthlyPayment);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement