Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 3, 2017 03:30
Show Gist options
  • Save codecademydev/8c344abd8da76e4e944326cce0d79adb to your computer and use it in GitHub Desktop.
Save codecademydev/8c344abd8da76e4e944326cce0d79adb to your computer and use it in GitHub Desktop.
Codecademy export
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.printIn("Error! You must take out a valid car loan");
}
else if(downPayment >= carLoan){
System.out.printIn("The car can be paid in full");
}
else if {
int remainingBalance = carLoan - downPayment;
int months = loanLength * 12;
int monthlyBalance = remainingBalance / months;
int interest = (monthlyBalance * interstRate) / 100;
int monthlyPayment = monthlyBalnace + interestRate;
System.out.printIn(monthlyPayment);
}
}
}
@animecafe
Copy link

Change the last "else if" to an "else". The instructions ask you to make 1 "if", 1 "else if", and 1 "else". The rest of your code is correct though. Just fix that 1 line.

Here's my code. It works correctly BTW....

public class CarLoan {
public static void main(String[] args) {

int carLoan = 10000;
    int loanLength = 3;
    int interestRate = 5;
    int downPayment = 2000;

if (carLoan <= 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);
  
 }
} // Closes main()

}; // Closes Class CarLoan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment