473,545 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mortgage Calculation Program

34 New Member
I'm trying to get this program to calualte the totals of 3 different mortgages using arrays.I need the program to calculate the loans to the end of each term. Can someone point me in the right direction, before I lose my mind!



Expand|Select|Wrap|Line Numbers
  1.  import java.math.*; 
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4.  
  5. public class mortgage3Loanswk5
  6. {
  7.     public static void main(String[]args)
  8.     {
  9.  
  10.     //Declare varibles//
  11.     double mortgage1, mortgage2, mortgage3, ammount;
  12.     ammount= 200000;//Principle loan//
  13.     double monthlyRate1, monthlyRate2, monthlyRate3;
  14. double[] iRate= {0.0575, 0.0550, 0.0535};//interest rates on 3 loans//
  15.     int[] term= {30, 15, 7};//number of years for loans//
  16.     double MP=(0);
  17.     int year= (0);
  18.     int month= (0);
  19.     int NewInterest1= (0);
  20.     int NewInterest2= (0);
  21.     int NewInterest3= (0);
  22.     int amount1= 200000;
  23.     int amount2= 200000;
  24.     int amount3= 200000;
  25.     double interest1= 0.0575;
  26.     double interest2= 0.055;
  27.     double interest3= 0.0535;
  28.     double []payment={(monthlyRate1), (monthlyRate2), (monthlyRate3)};
  29.     double []interest={(interest1), (interest2), (interest3)}; 
  30.  
  31.     String hold="";
  32.     Scanner scan=new Scanner(System.in);
  33.  
  34.  
  35.     DecimalFormat decimalPlaces=new DecimalFormat("0.00");
  36.     //Formulas used within this program//
  37.     monthlyRate1=(ammount*((iRate[0]/12)/(1-Math.pow((1+(iRate[0]/12)),-(term[0]*12)))));
  38.     interest1= amount1*(interest1/12);
  39.     loanamount1=(interest1+amount1)-(monthlyRate1));
  40.  
  41.     monthlyRate2=(ammount*((iRate[1]/12)/(1-Math.pow((1+(iRate[1]/12)),-(term[1]*12)))));
  42.     loanamount2=((interest2+amount2)-monthlyRate2);
  43.     interest2=(amount2*(interest2/12));
  44.  
  45.     monthlyRate3=(ammount*((iRate[2]/12)/(1-Math.pow((1+(iRate[2]/12)),-(term[2]*12)))));
  46.     interest3=(amount3*(interest3/12));
  47.     loanamount3=((interest3+amount3)-monthlyRate3);
  48.  
  49.     double []newmonthly={(loanamount1), (loanamount2), (loanamount3)};
  50.  
  51.     //loop begins here// 
  52.  
  53.     for(year=1; year<=term[0]; year++)
  54.     {
  55.     System.out.println();
  56.     System.out.println("Press\"Enter\"to continue.");
  57.     hold=scan.nextLine();
  58.  
  59.  
  60.     {
  61.  
  62.     }
  63.         }    
  64.  
  65. System.out.println("The interest of the loan is: "+iRate[0]*100+"%");    
  66. System.out.println("Monthly Payments for the 1st is:$" +decimalPlaces.format(monthlyRate1));
  67. System.out.println("The term of the loan is:"+term[0]+"years{"+term[0]*12+"months}");
  68. System.out.println("");
  69. System.out.println("The interest of the loan is: "+iRate[1]*100+"%");
  70. System.out.println("Monthly Payments for the 2nd loan is:$" +decimalPlaces.format(monthlyRate2));
  71. System.out.println("The term of the loan is:"+term[1]+"years{"+term[1]*12+"months}");
  72. System.out.println("");
  73. System.out.println("The interest of the loan is: "+iRate[2]*100+"%");
  74. System.out.println("Monthly Payments for the 3rd loan is:$" +decimalPlaces.format(monthlyRate2));
  75. System.out.println("The term of the loan is:"+term[2]+"years{"+term[2]*12+"months}");
  76. System.out.println("");
  77. }
  78.  
  79.  
  80.  
  81. }//End program//
  82.  
Mar 1 '07 #1
3 2580
r035198x
13,262 MVP
I'm trying to get this program to calualte the totals of 3 different mortgages using arrays.I need the program to calculate the loans to the end of each term. Can someone point me in the right direction, before I lose my mind!



Expand|Select|Wrap|Line Numbers
  1.  import java.math.*; 
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4.  
  5. public class mortgage3Loanswk5
  6. {
  7.     public static void main(String[]args)
  8.     {
  9.  
  10.     //Declare varibles//
  11.     double mortgage1, mortgage2, mortgage3, ammount;
  12.     ammount= 200000;//Principle loan//
  13.     double monthlyRate1, monthlyRate2, monthlyRate3;
  14. double[] iRate= {0.0575, 0.0550, 0.0535};//interest rates on 3 loans//
  15.     int[] term= {30, 15, 7};//number of years for loans//
  16.     double MP=(0);
  17.     int year= (0);
  18.     int month= (0);
  19.     int NewInterest1= (0);
  20.     int NewInterest2= (0);
  21.     int NewInterest3= (0);
  22.     int amount1= 200000;
  23.     int amount2= 200000;
  24.     int amount3= 200000;
  25.     double interest1= 0.0575;
  26.     double interest2= 0.055;
  27.     double interest3= 0.0535;
  28.     double []payment={(monthlyRate1), (monthlyRate2), (monthlyRate3)};
  29.     double []interest={(interest1), (interest2), (interest3)}; 
  30.  
  31.     String hold="";
  32.     Scanner scan=new Scanner(System.in);
  33.  
  34.  
  35.     DecimalFormat decimalPlaces=new DecimalFormat("0.00");
  36.     //Formulas used within this program//
  37.     monthlyRate1=(ammount*((iRate[0]/12)/(1-Math.pow((1+(iRate[0]/12)),-(term[0]*12)))));
  38.     interest1= amount1*(interest1/12);
  39.     loanamount1=(interest1+amount1)-(monthlyRate1));
  40.  
  41.     monthlyRate2=(ammount*((iRate[1]/12)/(1-Math.pow((1+(iRate[1]/12)),-(term[1]*12)))));
  42.     loanamount2=((interest2+amount2)-monthlyRate2);
  43.     interest2=(amount2*(interest2/12));
  44.  
  45.     monthlyRate3=(ammount*((iRate[2]/12)/(1-Math.pow((1+(iRate[2]/12)),-(term[2]*12)))));
  46.     interest3=(amount3*(interest3/12));
  47.     loanamount3=((interest3+amount3)-monthlyRate3);
  48.  
  49.     double []newmonthly={(loanamount1), (loanamount2), (loanamount3)};
  50.  
  51.     //loop begins here// 
  52.  
  53.     for(year=1; year<=term[0]; year++)
  54.     {
  55.     System.out.println();
  56.     System.out.println("Press\"Enter\"to continue.");
  57.     hold=scan.nextLine();
  58.  
  59.  
  60.     {
  61.  
  62.     }
  63.         }    
  64.  
  65. System.out.println("The interest of the loan is: "+iRate[0]*100+"%");    
  66. System.out.println("Monthly Payments for the 1st is:$" +decimalPlaces.format(monthlyRate1));
  67. System.out.println("The term of the loan is:"+term[0]+"years{"+term[0]*12+"months}");
  68. System.out.println("");
  69. System.out.println("The interest of the loan is: "+iRate[1]*100+"%");
  70. System.out.println("Monthly Payments for the 2nd loan is:$" +decimalPlaces.format(monthlyRate2));
  71. System.out.println("The term of the loan is:"+term[1]+"years{"+term[1]*12+"months}");
  72. System.out.println("");
  73. System.out.println("The interest of the loan is: "+iRate[2]*100+"%");
  74. System.out.println("Monthly Payments for the 3rd loan is:$" +decimalPlaces.format(monthlyRate2));
  75. System.out.println("The term of the loan is:"+term[2]+"years{"+term[2]*12+"months}");
  76. System.out.println("");
  77. }
  78.  
  79.  
  80.  
  81. }//End program//
  82.  
Explain what you have done and what you now need help with.
Mar 1 '07 #2
ghostrider
34 New Member
Well what I have done is created a program that displays the monthly cost for 3 different loans. Using the same principle, but different interest rates and number of years. So now I'm trying to figure out how to make it calculate the mortgages through the life of each loan using the same arrays and a for loop. So basically I need all the loans to be zeroed out at the end of each loan term.
Mar 1 '07 #3
DeMan
1,806 Top Contributor
Not necessatrily in good java (and I'm not sure whether answering the question but...).....
Expand|Select|Wrap|Line Numbers
  1. int month = 0;
  2. int originalTot = loanAmount;
  3. while(loanAmount < monthlyAmount)
  4. {
  5.   loanAmount = loanAmount - monthlyAmount;
  6.   month ++
  7. }
  8. System.out.println("The loan of " +originalTot + "was paid off in " + (month+1) + " months, with a final payment of " + loanAmount");
  9.  
Mar 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3260
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the program is doing I show a window which contains a progress bar and a label. At some point during the execution the state of the calculation is changed,...
4
6972
by: promiscuoustx | last post by:
The problem is that my code below used to run wonderfully, until the instructor decided that he wants to use characters instead of integers, and wants my code to trap the bad and have the program state that the user did not imput the correct values. Can someone help me figure out how to make my code work that way??? I have the majority of the...
3
4021
by: promiscuoustx | last post by:
I am trying to get my program to compile, but it will not complete. At line 79 it states, cannot convert 'float()()' to 'float' in assignment. Here is my code. #include <iostream> #include <iomanip> #include <cmath> #include <cctype> #include <stdlib.h> #include <sstream> using namespace std;
3
6675
by: cameron | last post by:
Hi I am new here in this forum: I am writing a C++ program to calculate a Montly Mortgage Payment where the loan amount is 200,000.00 with a 5.75% interest rate with a term of 30 years. My program compiles fine with no errors but my calculation is not working correctly, any suggestions would be great as this assignment is due on Monday:...
2
7862
by: phjones | last post by:
Need help programming mortagage calculator for 3 different loans 7 year, 15 year and 30 year. using java array I am a beginner with Java, This is what I have so far. Need to know if I am off the path, import java.math.*;//*loan calculator import java.text.*;//*formats numbers public class 3 Mortgage loans { // declare class...
1
9800
by: phjones | last post by:
please help resolve some error messages code is compling with errors see below the code. I am new at this please help! /** * @(#)3 Mortgage loans.java * * 3 Mortgage loans application * * Phyllis J Jones * Purpose to write a program in Java without a graphical user interface and have
1
6830
by: phjones | last post by:
This is not a class project.The program below is to display mortgage interest paid for each payment over the term of the loan and loan balance.It is program using array. However, I am receiving the following error message: --------------------Configuration: <Default>-------------------- C:\Program Files\Xinox...
1
2202
by: dylbin | last post by:
I am having trouble with the following program: Without using a G.U.I., using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term, I have to display the mortgage payment amount and then list the loan balance and interest paid for each payment over the term of the loan.
3
3605
by: zaidalin79 | last post by:
I have finally gotten my GUI to look like I want it to, but I am having trouble getting the calculations right. No matter what I put in there, it seems to calculate a large payment, and a very wrong amortization schedule... Here is what I have so far... package guiweek3; //imports necessary tools import java.io.*; import java.awt.*;...
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.