-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoan.java
More file actions
51 lines (47 loc) · 1.33 KB
/
Loan.java
File metadata and controls
51 lines (47 loc) · 1.33 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
package objectAndClass;
public class Loan {
//declaring instance variable
private double annualInterestRate;
private int numbersOfYears;
private double loanAmount;
private java.util.Date loanDate;
public Loan(){
this(2.5,1,1000);
}
public Loan(double annualInterestRate,int numbersOfYears,double loanAmount){
this.annualInterestRate=annualInterestRate;
this.numbersOfYears=numbersOfYears;
this.loanAmount=loanAmount;
loanDate= new java.util.Date();
}
public double getAnnualInterestRate(){
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate){
this.annualInterestRate=annualInterestRate;
}
public int getNumbersOfYears(){
return numbersOfYears;
}
public void setNumbersOfYears(int numbersOfYears){
this.numbersOfYears=numbersOfYears;
}
public double getLoanAmount(){
return loanAmount;
}
public void setLoanAmount(double loanAmount){
this.loanAmount=loanAmount;
}
public double getMonthlyPayment(){
double monthlyInterestRate=annualInterestRate/1200.0;
double monthlyPayment=loanAmount*monthlyInterestRate/(1-(1/Math.pow(1+monthlyInterestRate, numbersOfYears*12)));
return monthlyPayment;
}
public double getTotalPayment(){
double totalPayment=getMonthlyPayment()*numbersOfYears*12;
return totalPayment;
}
public java.util.Date getLoanDate(){
return loanDate;
}
}