-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloan2.java
More file actions
56 lines (44 loc) · 1.26 KB
/
loan2.java
File metadata and controls
56 lines (44 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Date;
public class Loan {
private double annualInterestRate;
private int numberOfYears;
private double loanAmount;
private Date loanDate;
public Loan() {
this(2.5, 1 , 100);
}
public Loan(double annualInterestRate, int numberOfYears, double loanAmount) {
this.annualInterestRate = annualInterestRate;
this.numberOfYears = numberOfYears;
this.loanAmount = loanAmount;
loanDate = new Date();
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public int getNumberOfYears() {
return numberOfYears;
}
//loanAmount must be calculated
public void setNumberOfYears(int numberOfYears) {
this.numberOfYears = numberOfYears;
}
//return loan Amount
public double getLoanAmount() {
return loanAmount;
}
public void setLoanAmount(double loanAmount) {
this.loanAmount = loanAmount;
}
public double getMonthlyPayment() {
double monthlyInterestRate = annualInterestRate / 1200;
double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / Math.pow( 1 + monthlyInterestRate, numberOfYears * 12)));
return monthlyPayment;
}
public Date getLoanDate() {
return loanDate;
}
}