Java Loan Calculator


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
I need to get answer to print out 233 not 227. Can you see what wrong with my logic? the values are 100% correct. I need the monthlyPayment to print out 233. Let me know if you find the error. Thank you

```

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);
	}
}

}

<do not remove the three backticks above>

#2

See, everything seems to be fine except an indentation error which would not be an error for the compiler. The code must compile without an error.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.