-
-
Save codecademydev/a54147f155c8788808d38de9af3b6beb to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + interestRate); | |
System.out.println(monthlyPayment); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment