In: Computer Science
Hello, I am just having a hard time understanding this question. The question is below. I am not supposed to write a program but instead in regular english sentence form just name the methods, fields, and variables I would use for this loan class. Im not really sure what a loan class means as well, thank you for your help.
USING JAVA Given a Loan class, name the necessary fields and methods that we would need in this class. Be creative in your naming of variables and methods.
/**************************************
* Loan *
*----------------------------------- *
* -annualInterestRate: double *
* -numberOfYears: int *
* -loanAmount: double *
* -loanDate: java.util.Date *
* +Loan() *
* +Loan(annualInterestRate: double, *
* numberOfYears: int,loanAmount: *
* double) *
* +getAnnualInterestRate(): double *
* +getNumberOfYears(): int *
* +getLoanAmount(): double *
* +getLoanDate(): java.util.Date *
* +setAnnualInterestRate( *
* annualInterestRate: double): void *
* +setNumberOfYears( *
* numberOfYears: int): void *
* +setLoanAmount( *
* loanAmount: double): void *
* +getMonthlyPayment(): double *
* +getTotalPayment(): double *
**************************************/
// Implement Serializable
public class Loan implements java.io.Serializable {
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 an new annualInterestRate */
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
/** Return numberOfYears */
public int getNumberOfYears() {
return numberOfYears;
}
/** Set a new numberOfYears */
public void setNumberOfYears(int numberOfYears) {
this.numberOfYears = numberOfYears;
}
/** Return loanAmount */
public double getLoanAmount() {
return loanAmount;
}
/** Set a new loanAmount */
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;
}
/** Return loan date */
public java.util.Date getLoanDate() {
return loanDate;
}
@Override /** Override the toString method in the Object class */
public String toString() {
return "Date: " + loanDate + "\nAnnual interest Rate: " +
annualInterestRate + "\nYears: " + numberOfYears +
"\nLoan amount: " + loanAmount;
}
}
Note, if you like the answer, please consider upvoting. ;-)