I made this project (https://www.codecademy.com/courses/learn-java/projects/loan-payment-calculator?action=resume_content_item) more complex than it was asked. In order to add more instances.
And it works. But I need to know is there any idea to make code better or it’s fine?
public class CarLoan {
int carLoan;
int loanLength;
int interestRate;
int downPayment;
public CarLoan(int loan, int loanl, int interestr, int downPay) {
carLoan = loan;
loanLength = loanl;
interestRate = interestr;
downPayment = downPay;
if (loanl <= 0) {
System.out.println("Error! You must take out a valid car loan.");
} else if (downPay >= loan) {
System.out.println("The car can be paid in full.");
}
}
public void monthyPayment() {
int remainingBalance = carLoan - downPayment;
int months = loanLength * 12;
int monthlyBalance = remainingBalance / months;
int interest = (monthlyBalance * interestRate) / 100;
int monthlyP = monthlyBalance + interest;
System.out.println(monthlyP);
}
public static void main(String[] args) {
CarLoan client1 = new CarLoan (10000, 3, 5, 2000);
client1.monthyPayment();
CarLoan client2 = new CarLoan (10000, 4, 2, 500);
client2.monthyPayment();
}
}