So I'm in the final days of being able to turn this in, yes it is a homework assignment, but I've almost got it completely done. In fact I'm only having issues with like the last 8 lines. (at least that's all that is causing an error right now.)

Here is what is happening. I designed a mortgage calculator last week that displayed the Loan Amount, the terms, the interest and then calculated the monthly payment. This week I need to make it figure out the Principle Balance and the Interest Paid each month. This will go off the screen so I tried to use loops. Not sure if I know what I'm doing. Just when I think I got it, I dont.

* Service Request: SR-mf-03 Mortgage Payment Calculator
 * Purpose: Complete Change Request #1 in Service Request SR-mf-003,
            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.
            Insert comments in the program to document the program.
  * Mortgage Payment Formula From http://www.rihomesearch.com/15.php.
 	P= Principal
 	I= Interest Rate
 	L= Length
 	J= Monthly Interest
 	N= Number of Month Loan is Amortized
  * Monthly payment (M) formula:
        M = P * ( J / (1 - (1 + J)** -N))
  */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.*;
public class MortgagePaymentCalc4
	{
	/* Calculate mortgage payment.  The calculation is based on the fixed input which
	 * are set by variables PrincipleBalance, MonthlyInterest, and Months.
	 */
	public static void main(String[] args)
		{

		// Declare Variables
		int Months;
		double MonthlyPayment, PrincipleBalance, MonthlyInterest;

		// Initialize Variables
		PrincipleBalance = 200000;		// Mortgage Amount
		MonthlyInterest = 5.75 / (12*100);	// Monthly Interest
		Months = 30 * 12;			// Mortgage Length
		MonthlyPayment = 0;			// Monthly Payment

		// Calculate Monthly Payment
		MonthlyPayment = PrincipleBalance * (MonthlyInterest / (1 - Math.pow(1/(1+MonthlyInterest), Months)));

		// Round Cent Decimal
		DecimalFormat RoundtoCents = new DecimalFormat("0.00");

		//Output Calculation
		System.out.println();
		System.out.println("\t\t\tMcBride Financial Services");
		System.out.println("\t\t   Monthly Mortgage Payment Calculator");
		System.out.println();
		System.out.println();
		System.out.println("\t\t\tPrincipal Mortgage: $"+Math.round(PrincipleBalance)+".");
		System.out.println("\t\t\tInterest Rate: "+MonthlyInterest*12*100+"%.");
		System.out.println("\t\t\tTerm: "+Months/12+" years");
		System.out.println();
		System.out.println();
		System.out.println("\t\t\tMonthly Payment: $"+RoundtoCents.format(MonthlyPayment)+".");
		System.out.println();
	}


public void listBal()
	{

		        System.out.println();
		        System.out.println("Month     " + "\t" + "Amount     " + "\t\t" + "Interest    " + "\t" + "Balance    ");

				// Declare Variables
				int periods = 1, Months;
		        double Balance, Interest, MonthlyPayment, PrincipleBalance, MonthlyInterest;
		        while(periods <=Months)
		        {
		        int i = 0;
		         while(i <10)
		         {
		            Balance = PrincipleBalance*(1+MonthlyInterest) - MonthlyPayment; //Calculation of Balance
		            Interest = PrincipleBalance*MonthlyInterest; //Calculation of Interest
		            //Now print using the round to two decimal places
		            System.out.println(""+periods +"\t\t"+(Math.round(PrincipleBalance*100.00)/100.00)+"\t\t"+(Math.round(Interest*100.00)/100.00)+"\t\t"+(Math.round(Balance*100.00)/100.00));
		            PrincipleBalance = Balance; //Set the Principal for next round to the Balance of previous month
		            periods++;
		            i++;
		        }
		      System.out.println("Press Enter to continue..");
		        BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
		        String str = "";
		        try
		        {
		            str = br.readLine();
		        }
		        catch (IOException ioe) { System.out.println(ioe); }
		    }
		 }

		    {

		        MortgagePaymentCalc4 mc2 = new MortgagePaymentCalc4(25, (double)200000, (double)0.0575);

		        //Calculate Monthly payment
		        mc2.CalcMonthlyPayment();
		        //Show the output
		        mc2.DisplayMonthlyPayment();
	            mc2.listPrincipleBalance();
}
}

Any help or points in the right direction would be greatly appreciated! Thanks!

Recommended Answers

All 5 Replies

So I just solved the constructor issue, left it blank as a blank () instead of the 25, double, double stuff.

Now if only posting this would make me figure out the last mc2. issue. It's pointing to the period on all three of those. Any idea?

Because you are trying to call methods on the class that you have not written. Those methods don't exist in the code that you posted.

Because you are trying to call methods on the class that you have not written. Those methods don't exist in the code that you posted.

O.k. here is my new stuff. It compiles successfully but it only displays my original calculator, not the interest and principle, looping.

What am I missing??

* Service Request: SR-mf-03 Mortgage Payment Calculator
 * Purpose: Complete Change Request #1 in Service Request SR-mf-003,
            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.
            Insert comments in the program to document the program.
 * Filename: MortgagePaymentCalc.java
 * Developed: December 20, 2007
 * Version: 2
 * Mortgage Payment Formula From http://www.rihomesearch.com/15.php.
 	P= Principal
 	I= Interest Rate
 	L= Length
 	J= Monthly Interest
 	N= Number of Month Loan is Amortized
  * Monthly payment (M) formula:
        M = P * ( J / (1 - (1 + J)** -N))
  */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.*;
public class MortgagePaymentCalc4
	{
	/* Calculate mortgage payment.  The calculation is based on the fixed input which
	 * are set by variables PrincipleBalance, MonthlyInterest, and Months.
	 */
	public static void main(String[] args)
		{

		// Declare Variables
		int Months;
		double MonthlyPayment, PrincipleBalance, MonthlyInterest;

		// Initialize Variables
		PrincipleBalance = 200000;		// Mortgage Amount
		MonthlyInterest = 5.75 / (12*100);	// Monthly Interest
		Months = 30 * 12;			// Mortgage Length
		MonthlyPayment = 0;			// Monthly Payment

		// Calculate Monthly Payment
		MonthlyPayment = PrincipleBalance * (MonthlyInterest / (1 - Math.pow(1/(1+MonthlyInterest), Months)));

		// Round Cent Decimal
		DecimalFormat RoundtoCents = new DecimalFormat("0.00");

		//Output Calculation
		System.out.println();
		System.out.println("\t\t\tMcBride Financial Services");
		System.out.println("\t\t   Monthly Mortgage Payment Calculator");
		System.out.println();
		System.out.println();
		System.out.println("\t\t\tPrincipal Mortgage: $"+Math.round(PrincipleBalance)+".");
		System.out.println("\t\t\tInterest Rate: "+MonthlyInterest*12*100+"%.");
		System.out.println("\t\t\tTerm: "+Months/12+" years");
		System.out.println();
		System.out.println();
		System.out.println("\t\t\tMonthly Payment: $"+RoundtoCents.format(MonthlyPayment)+".");
		System.out.println();
	}
private int Period; //Instance variables
       private double LoanAmount;
       private double MonthlyInterestRate;
       private double MonthlyPayment;
int Months;
		double PrincipleBalance, MonthlyInterest;

//constructor for user defined values
       public MortgagePaymentCalc4(int _Period, double LA, double IR){
           Period = _Period;
           LoanAmount = LA;
           MonthlyInterestRate = IR/12;
           // Initialize Variables
		PrincipleBalance = 200000;		// Mortgage Amount
		MonthlyInterest = 5.75 / (12*100);	// Monthly Interest
		Months = 30 * 12;			// Mortgage Length
		MonthlyPayment = 0;			// Monthly Payment
       }

       public int GetPeriod(){
           return Period;
       }
       public void SetPeriod(int Period){
           this.Period = Period;
       }

       public double GetLoanAmount(){
           return LoanAmount;
       }
       public void SetLoanAmount(double LoanAmount){
           this.LoanAmount = LoanAmount;
       }

       public double GetMonthlyInterestRate(){
           return MonthlyInterestRate;
       }
       public void SetMonthlyInterestRate(double InterestRate){
           this.MonthlyInterestRate = InterestRate/12;
       }
       public void CalcMonthlyPayment(){
       MonthlyPayment = LoanAmount*Math.pow(1+MonthlyInterestRate, Period)*MonthlyInterestRate/(Math.pow(1+MonthlyInterestRate, Period) -1);
       }
       public String ToString (double value){
       return Double.toString(value);
      }
       public void DisplayMonthlyPayment(){
       System.out.println("Monthly Payment = $" +ToString(MonthlyPayment));
       }

public void listPrincipleBal()
	{

		        System.out.println();
		        System.out.println("Month     " + "\t" + "Amount     " + "\t\t" + "Interest    " + "\t" + "Balance    ");

				// Declare Variables
				int periods = 1, Months;
		        double Balance, Interest, MonthlyPayment, PrincipleBalance, MonthlyInterest;

						// Initialize Variables
						PrincipleBalance = 200000;		// Mortgage Amount
						MonthlyInterest = 5.75 / (12*100);	// Monthly Interest
						Months = 30 * 12;			// Mortgage Length
						MonthlyPayment = 0;			// Monthly Payment

		        while(periods <=Months)
		        {
		        int i = 0;
		         while(i <10)
		         {
		            Balance = PrincipleBalance*(1+MonthlyInterest) - MonthlyPayment; //Calculation of Balance
		            Interest = PrincipleBalance*MonthlyInterest; //Calculation of Interest
		            //Now print using the round to two decimal places
		            System.out.println(""+periods +"\t\t"+(Math.round(PrincipleBalance*100.00)/100.00)+"\t\t"+(Math.round(Interest*100.00)/100.00)+"\t\t"+(Math.round(Balance*100.00)/100.00));
		            PrincipleBalance = Balance; //Set the Principal for next round to the Balance of previous month
		            periods++;
		            i++;
		        }
		      System.out.println("Press Enter to continue..");
		        BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
		        String str = "";
		        try
		        {
		            str = br.readLine();
		        }
		        catch (IOException ioe) { System.out.println(ioe); }
		    }
		 }

		    {

		        MortgagePaymentCalc4 mc3 = new MortgagePaymentCalc4(25, (double)200000, (double)0.0575);

		        //Calculate Monthly payment
		        mc3.CalcMonthlyPayment();
		        //Show the output
		        mc3.DisplayMonthlyPayment();
	            mc3.listPrincipleBal();
}
}

I guess no one knows how to do this. I just turned it in not working, instructor wouldn't help me, classmates wouldn't help me, oh well.

Member Avatar for iamthwee

You learn by your mistakes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.