-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoan.java
80 lines (64 loc) · 2.08 KB
/
Loan.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public class Loan {
private double annualInterestRate;
private int numberOfYears;
private double loanAmount;
private java.util.Date loanDate;
//Default constructor
public Loan(){
this(2.5, 1, 1000);
}
//Construct a loan with specified annual interest rate, number of years, and loan amount
public Loan(double annualInterestRate, int numberOfYears, double loanAmount) {
this.annualInterestRate = annualInterestRate;
this.numberOfYears = numberOfYears;
this.loanAmount = loanAmount;
loanDate = new java.util.Date();
}
//Return annualInterestRate
public double getAnnualInterestRate(){
return annualInterestRate;
}
//Set a new annualInterestRate
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
//Return numberOfYears
public int getNumberOfYears(){
return numberOfYears;
}
//Set a new number of years
public void setNumberOfYears(int numberOfYears) {
this.numberOfYears = numberOfYears;
}
//Return loanAmount
public int getNumberOfYears(){
return numberOfYears;
}
//Return numberOfYears
public int getNumberOfYears(){
return numberOfYears;
}
//Set a new number of years
public void setNumberOfYears() {
this.numberOfYears = numberOfYears;
}
//Return loan amount
public double getLoanAmount() {
return loanAmount;
}
//set a new loan amount
public void setLoanAmount(double loanAmount) {
this.loanAmount = loanAmount;
}
//Find monthly payment
public double getMonthlyPayment(){
double monthlyInterestRate = annualInterestRate / 1200;
double monthlyPayment = loanAmount * monthlyInterestRate/ (1-(1/Math.pow(1 + monthlyInterestRate, numberOfYears * 12)));
return monthlyPayment;
}
//Find total payment
public double getTotalPayment(){
double totalPayment = getMonthlyPayment() * numberOfYears *12;
return totalPayment;
}
}