?
Solved

I am trying loop mortgage payments

Posted on 2005-03-15
6
Medium Priority
?
267 Views
Last Modified: 2010-03-31
import java.text.*;

public class mortgage      
{
   //private member variables declared static for now
   

double loanamount  = 200000.00;      //Total mortgage payment
double loanterm    = 30.00;      //Length of years for loan
double interestrate  = 0.0575;      //Interest rate for loan
         

double monthlyprinciple;
double loanbalance = 0.0;  
double monthinterest;  

      int payment = 0;
      int months = 0;      

         
      void main(String[] args)  //Entry point. Only one can exist per class and invocation.
         {
 
        double monthlyinterest = interestrate/12;      //Months in a year for loan
       double monthlyterm = loanterm*12;      //Monthly precentage rate
 
           //convert to monthly terms
      double monthlytotal=(Math.pow((1+monthlyinterest),monthlyterm)-1)/(monthlyinterest*Math.pow((1+monthlyinterest),monthlyterm));
        double monthlypayment = loanamount/monthlytotal;
 
           //Format values as currency for the default locale.
          String monthlypaymenttotal = java.text.NumberFormat.getCurrencyInstance().format(monthlypayment);
         String totalloanamount = java.text.NumberFormat.getCurrencyInstance().format(loanamount);
 
          //Output the results by field.
         System.out.println("-----------------------------------------------------------");
         System.out.println("Total Loan Amount: " + totalloanamount);
         System.out.println("Interest Rate: " + 100 * interestrate);
         System.out.println("Loan Term: " + loanterm);
         System.out.println("-----------------------------------------------------------");
          System.out.println("Total Monthly Payment: " + monthlypaymenttotal);

      while (loanamount >= 0.01) //Loop ends when loan is below one penny
            {   //loop loan payment
                        monthlyinterest = (loanamount * interestrate);
                        monthlyprinciple = monthlypayment - monthinterest;
                        loanbalance = loanamount - monthlyprinciple;   //calculates new principal
                        loanamount = loanbalance;
                        payment++;
                        months++;
                        if (months == 6)
                        {   //pauses to show payments
                                  pause(3600);
                                       months= 0;
                                  }
                        System.out.println("\n\nPayment Number:" + payment+ "\n------------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount of Interest Paid = " + form.format(monthinterest));

                  
               }
      }

         public static void pause(int duration) {   //sets up pause object
        try
      {
            Thread.sleep(duration);
      }
      catch (InterruptedException e) {}
   }
}


Error
mortgage.java:74: cannot resolve symbol
symbol  : variable form
location: class mortgage
                        System.out.println("\n\nPayment Number:" + payment+ "\n
-----------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount o
 Interest Paid = " + form.format(monthinterest));

                                          ^
mortgage.java:74: cannot resolve symbol
symbol  : variable form
location: class mortgage
                        System.out.println("\n\nPayment Number:" + payment+ "\n
-----------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount o
 Interest Paid = " + form.format(monthinterest));


                     ^
2 errors

E:\Documents and Settings\sublime\Desktop\University of Phoenix\POS_406\Program
>
0
Comment
Question by:sublime76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 13552446
Hi. Try adding this:

        NumberFormat form = NumberFormat.getCurrencyInstance();

just before the System.out.println referencing form on line 74.

BTW, when you try to test this you'll find that it won't run (or I don't think it will) because the main method must be defined as public static. Change your class like this and you'll get better results:

Replace:

    void main(String[] args) {

with:

    public static void main(String[] args) {
        new Mortgage().run();
    }
   
    public void run() {

Best regards,
Jim Cakalic
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 2000 total points
ID: 13552476
Oh, yeah -- make sure to add an import of java.text.NumberFormat. Eclipse does it for me so I sometimes forget to make it part of my post.

Jim
0
 

Author Comment

by:sublime76
ID: 13559957
Thanks but I already fixed it.  Here is what the program needs to look like.  I do appreciate you help though.

import java.text.*;

class mortgage      
{
   //private member variables declared static for now
   
      public static void main(String[] args)  //Entry point. Only one can exist per class and invocation.
      
      {

      double loanamount  = 200000.00;      //Total mortgage payment
      double loanterm    = 30.00;      //Length of years for loan
      double interestrate  = 0.0575;      //Interest rate for loan
         

      double monthlyprinciple;
      double loanbalance = 0.0;  
      double monthinterest;  

      int payment = 0;
      int months = 0;      

               
         
 
        double monthlyinterest = interestrate/12;      //Months in a year for loan
       double monthlyterm = loanterm*12;      //Monthly precentage rate
 
      NumberFormat form = NumberFormat.getCurrencyInstance();   //creates form object

           //convert to monthly terms
      double monthlytotal=(Math.pow((1+monthlyinterest),monthlyterm)-1)/(monthlyinterest*Math.pow((1+monthlyinterest),monthlyterm));
        double monthlypayment = loanamount/monthlytotal;
 
           //Format values as currency for the default locale.
          String monthlypaymenttotal = java.text.NumberFormat.getCurrencyInstance().format(monthlypayment);
         String totalloanamount = java.text.NumberFormat.getCurrencyInstance().format(loanamount);
 
          //Output the results by field.
         System.out.println("-----------------------------------------------------------");
         System.out.println("Total Loan Amount: " + totalloanamount);
         System.out.println("Interest Rate: " + 100 * interestrate);
         System.out.println("Loan Term: " + loanterm);
         System.out.println("-----------------------------------------------------------");
          System.out.println("Total Monthly Payment: " + monthlypaymenttotal);

      while (loanamount >= 0.01) //Loop ends when loan is below one penny
            {   //loop loan payment
                        monthinterest = (loanamount * interestrate);
                        monthlyprinciple = monthlypayment - monthinterest;
                        loanbalance = loanamount - monthlyprinciple;   //calculates new principal
                        loanamount = loanbalance;
                        payment++;
                        months++;
                        if (months == 6)
                        {   //pauses to show payments
                                  pause(3600);
                                       months= 0;
                                  }
                        System.out.println("\n\nPayment Number:" + payment+ "\n------------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount of Interest Paid = " + form.format(monthlyinterest));

                  
               }
      }

         public static void pause(int duration) {   //sets up pause object
        try
      {
            Thread.sleep(duration);
      }
      catch (InterruptedException e) {}
   }
}
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 13560375
I'm glad your problem is solved. But only a C?

Regards
Jim
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question