My output display this: Mortgagecalculator@7ced01
The output should display Years: 30, Loan Amount $200000.00, Interest Rate: .0575, and Monthly Payment: Calculated by Math.POW. Then a list of loan balance and interest paid for each payment over the term of the loan should scroll off the screen, but need loops to display a partial list, hesitate and then display more of the list. Do not use a graphical user interface. Please insert comments in the program so I can understand the fixes.
The setter and getters must stay in MortgageCalculator.java and everything should output from main (Driver.java).
FILE: DRIVER.JAVA
import java.util.*;
/***Created on June 27, 2004, 5:07 PM
* Java Programming Project Workshop 3 -
* Problem statement - Create a driver for the Mortgage Calculator
* Scope - declare, initialize and set values and display mortgage calculator
* @author TERRY PARKER
*/
public class Driver {
/**
* @param args the command line arguments
*/
public static void main(String args[]){//The main part of Mortgage Calculator begins here
Mortgagecalculator mCalc;
mCalc = new Mortgagecalculator();
mCalc.setYears(30);
mCalc.setLoanAmount(200000.0);
mCalc.setInterestRate(.0575);
System.out.println(mCalc.toString());//Display the contents
}//end of group
}//closing bracket
FILE: MORTGAGE CALCULATOR.JAVA
/** mortgagecalculator.java
* Created on June 27, 2004, 5:07 PM
* Java Programming Project Workshop 2 -
* Problem statement - Create a Mortgage Calculator WITHOUT a graphical user interface
* Purpose - provide a user-friendly service to potential users for accurately planning mortgage and other types of loans
* Scope - The mortgage calculator must display the mortgage payment amount given the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage.
* This program must have hard code amount = 200,000, term= 30 years, and the interest rate = 5.75% in class driver.java
* Algorithm - standard loan calculation with fixed number of payments:
* Monthly Payment = Principal * (InterestRate / (1 - (InterestRate + 1) - 12 * Periods)
*
* Inputs:
* Principal = $200,000
* Interest Rate = 0.0575
* Periods = 360
*
* Output:
* Monthly Payment =
*
* @author TERRY PARKER
* NETBEANS IDE 3.6*/
public class Mortgagecalculator{
/** Creates a static mortgagecalculator */
public int years;//define variables
public double loanAmount;
public double interestRate;
public double monthlyPayment;
public void setYears(int inYears)//setter
{
years=inYears;
}//end set years
public int getYears()//getter
{
return years;
}//end get years
public void setLoanAmount(double inLoanAmount)//setter
{
loanAmount=inLoanAmount;
}//end set loanAmount
public double getLoanAmount()//getter
{
return loanAmount;
}//end get loanAmount
public void setInterestRate(double inInterestRate)//setter
{
interestRate=inInterestRate;
}//end set interestRate
public double getInterestRate()//getter
{
return interestRate;
}//end get interestrate
public void CalcMonthlyPayment()
{
monthlyPayment=loanAmount*Math.pow(1 + interestRate, years) * interestRate/(Math.pow(1 + interestRate, years) -1);
}
public String toString(double value){//strings are used to store text and variables
String retString = new String();
retString = "Values:";
retString = retString + " years=" + years;
retString = retString + " loanAmount=" + loanAmount;
retString = retString + " interestRate=" + interestRate;
retString = retString + " monthlyPayment=" + monthlyPayment;
return retString;
}//end group
}//closing bracket