Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,310 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 861 people online right now. Registration is fast and FREE... Join Now!




Mortgage Array skips a pause?

 
Reply to this topicStart new topic

Mortgage Array skips a pause?

sir_gadget
19 Apr, 2006 - 10:47 AM
Post #1

New D.I.C Head
*

Joined: 3 Apr, 2006
Posts: 3


My Contributions
Write a program that calcualtes the payment anount, interest paid, and loan balance after each payment for a loan of 200000 using an array to step through three interest rates and loan terms.

In the following code I have asked the program to "press any key to continue" after each individual interest rate and loan term is completed so the user will know when the next interest rate and term is going to be displayed. The problem is that the "press any key to contiune" only works the first and third time. What am I missing?

CODE
 Author Derek Williamson
 Version 4.0
 Created on April 18, 2006
 To calculate and display a monthly mortgage payment for three different
 terms associated with three different interest rates. The mortgage amount is 200,000,
 the interest is 5.35%, 5.50%, 5.75% and the terms are 7, 15, and 30 years.
*/

import java.text.DecimalFormat;

public class mortgageCalculator4
{

    public static void main(String[] args) throws Exception
 {
 //Declares variables used to hold the financial and term data.  
 double mortgageAmount = 200000.00;
 double[] interestRate = {.0535, .0550, .0575};
 double interest = 0;
 int[] termMonths = {84, 180 ,360};
 double months = 360;
 double temp = 0;
 double monthlyPayment = 0;
 double interestPaid = 0;
 double principalPaid = 0;
 double mortgageBalance = 200000;
 double lineCount = 3;
 DecimalFormat money = new DecimalFormat("$0.00");
 int i;
 int j;
 
 //steps through the array and displays the payment amount.
 for (i = 0; i <= 2; i++){  
 lineCount = 10;
     
 for (j = 0; j <= termMonths[i]; j++){
 
 mortgageAmount=200000;
 mortgageBalance = 200000;
 
 
 
   
 //formula to calculate monthly payment amount
 monthlyPayment = (mortgageAmount*(interestRate[i]/12)) / (1 - 1 /Math.pow((1 + interestRate[i]/12), termMonths[i]));
     
 //Prints the mortgage calculator
 System.out.println("Mortgage Calculator");
 System.out.println("Your payment for a " +(money.format(mortgageAmount)) + " mortgage over a term of");
 System.out.println((termMonths[i]/12) + " years with an interest rate of " + (interestRate[i]*100)+ "% will be " +(money.format(monthlyPayment)) + " a month.");
 System.out.println();
 
 System.out.println("Press Enter to Continue.");
 System.in.read ();
     
   
 //Starts loop statement,  declares formula for loan balance and interest paid.
 while(termMonths[i] > 0) {
 
    
 
 //reduces the term one month at a time
 months = (termMonths[i] --);
 
 //calculates the interest paid and resets the mortgage balance to reflect payment.
 temp = (1 - 1 /Math.pow((1 + interestRate[i]/12), months));
 interestPaid = (monthlyPayment * temp);
 mortgageBalance = (mortgageAmount - monthlyPayment + interestPaid);
       
 
     
     //Displays the payment amount, mortgage balance, and interest paid.
 System.out.println("After a payment of: " +(money.format(monthlyPayment)));
 System.out.println("The current balance of your mortgage is: " +(money.format(mortgageBalance)));
 System.out.println("This months interest paid on the mortgage is: " +(money.format(interestPaid)));
 System.out.println();
 
 //sets a new mortgage amount reflecting the payment.
 mortgageAmount = mortgageBalance;
 

 
 
 
 
 }
 //Pauses screen
 if (lineCount > 0) {
 lineCount--;
 
 try {
 Thread.sleep(3000);
 } catch (InterruptedException e) {
 }
 }
 }
 }
 //Stops loop statement
 //if (termMonths[i] <= 0){
 //System.out.println("CONGRATULATIONS! Your mortgage is paid in full!");
 //}      
     
}    }


User is offlineProfile CardPM
+Quote Post


tody4me
RE: Mortgage Array Skips A Pause?
19 Apr, 2006 - 02:28 PM
Post #2

Banned
*****

Joined: 12 Apr, 2006
Posts: 1,398



Thanked: 9 times
Dream Kudos: 100
My Contributions
check to see if there is a exception thrown, and if so give some message back to the user. The way that you have it now, you do catch the exception, but do nothing with it.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 07:19PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month