Need Alternate Code To Sleep
I wrote this code but I need to replace "thread.sleep" with something else that pretty much does the same thing. Any suggestions?
Here is the code:
import java.lang.*;
import java.text.DecimalFormat;
class mortgagePaymentAmount
{
publicstaticvoid main ( String[] args )
{
System.out.println("\nMortgage Program v5");//Should print out a header
//Declare and construct variables
finalint loanAmount = 200000;
//Arrays
//int months = 360;
int[] months={ 84, 180, 360};
//double interest = .0575;
double[] interest={ .0535, .055, .0575};
DecimalFormat df =new DecimalFormat("0.##");//DecimalFormat derived from http://forum.java.sun.com/
//Calculations
double monthlyPayment = (loanAmount * (interest[0]/12.0))/(1 - 1 /Math.pow((1 + interest[0]/12.0), months[0]));
double interestPaid = (interest[0]/12.0) * loanAmount;
double principal = monthlyPayment - interestPaid;
double balance = loanAmount - principal;
double newBalance = balance - principal;
double totalInterestPaid = interestPaid * months[0];
double totalPrincipal = principal * months[0];
double newInterest = (interest[0]/12) * balance;
//List loan balance and interest paid loop
int paymentNum=1;
try
{
for (int j = 0; j < months.length; j++)
{
monthlyPayment = (loanAmount * (interest[j]/12.0))/(1 - 1 /Math.pow((1 + interest[j]/12.0), months[j]));
interestPaid = (interest[j]/12.0) * loanAmount;
principal = monthlyPayment - interestPaid;
paymentNum = 1;
String newLine = System.getProperty("line.separator");//To clean up some line breaks from http://leepoint.net/notes-java/io/10file/sys-indep-newline.html
System.out.println(newLine + newLine +"Mortgage is: $" + loanAmount);
System.out.println("Term is: " + months[j] +" months or " + months[j]/12 +" years.");
System.out.println("Interest rate is: " + interest[j] +" or " +interest[j]*100 +"%");
System.out.println("Mortgage payment amount: $" + df.format(monthlyPayment));//Display the mortgage payment amount
balance = loanAmount - principal;
for (double i=balance; i >= 0; i-=principal)
{
System.out.println("Payment " + paymentNum +"\tBalance: $" + (df.format(i)) +" \tInterest paid: $" + (df.format(interestPaid)));
//If I want to display the principal, include this: " \tDisplay principal: $" + (df.format(principal)) +
principal = monthlyPayment - (interest[j]/12) * i;
interestPaid = (interest[j]/12.0) * i;
if (paymentNum > 0)
{
paymentNum++;
}
if (paymentNum > 20)
{
Thread.sleep(500);
}
}
}
}
catch (InterruptedException ex)//Sierra, K. Bates, B. (2005). "Head First Java". p.502
{
ex.printStackTrace();
}
}
}
Thanks!

