Hello Everyone!
I have a homework assignment due and I am having a problem with an compiling it to get an output.
This is my first and only Java class.
Can someone please tell me what I am doing wrong?
Thanks in advance.
/*
Programmer:Steve A. Massiah
Date:01/29/09
Course:PRG/420
File: McBrideCR1.java
Requestor:Dwain Hammer
Request Description:Write the program in Java (without a graphical user interface) using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term.
Display the mortgage payment amount and then list the loan balance and interest paid for each payment over the term of the loan.
If the list would scroll off the screen, use loops to display a partial list, hesitate, and then display more of the list.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class McBrideCR1 {
/** 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 / 12, years * 12) * (interestRate / 12) / (Math.pow(1 + interestRate / 12, years * 12) - 1);
}// Divide the yearly interest rate of 5.75% by 12 to get monthly ineterst rate
// Multiply the number of years by 12 to get the number of months
// Formula for monthly payment: monthlyPayment = [P((1+r)^n)*r]/[(1+r^n)-1], where r and n are calculated as above.
// This calculation is taken from the following webpage:
// http://www.dreamincode.net/
public String toString() {//strings are used to store text and variables
return "Mortgage Information" + "n" + "Loan Amount: $" + loanAmount + "n" + "Interest Rate: " + interestRate + "%" + "n" + "Term: " + (years * 12) + " months" + "n" + "Monthly Payment: $" + (Math.round(monthlyPayment * 100.00) / 100.00);//Using the round to two decimal places
}
public void schedule() {//print schedule and scroll
System.out.println();
System.out.println("Month " + "t" + "Amount " + "tt" + "Interest " + "t" + "Balance ");
int counter = 1;
double Balance, Interest;
while (counter <= years * 12) {
int scrollCounter = 0;
while (scrollCounter < 30) {
Balance = loanAmount * (1 + interestRate / 12) - monthlyPayment; //Calculation of Balance
Interest = loanAmount * interestRate / 12; //Calculation of Interest
//Now print using the round to two decimal places
System.out.println("" + counter + "tt" + (Math.round(loanAmount * 100.00) / 100.00) + "tt" + (Math.round(Interest * 100.00) / 100.00) + "tt" + (Math.round(Balance * 100.00) / 100.00));
loanAmount = Balance; //Set the Principal for next round to the Balance of previous month
counter++;
scrollCounter++;
}
System.out.println("Press Enter to contiune..");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
String str = "";
try {
str = br.readLine();
} catch (IOException ioe) {
System.out.println(ioe);
}
}
}//end group
}//closing bracket