I am needing to put a pause in between each mortgage calculation and do not know what the C equivalant of getchar() is in Java. Here is the code I have so far, after it is finished with the first mortgage at 30 years I want the user to have to press enter to continue to the next rate. Help is appreciated.

``````import java.io.*;  // java input output package
import java.text.DecimalFormat; // allows placement of decimal

{
public static void main(String[] args)
{

double Loan, NewBal, MIP;
double Rate, MonthlyInterest, Payments; //double precision variables

//assign values to variables
Loan= 200000; // loan amount
Rate = .0575; //interest rate
MonthlyInterest = Rate / 12; // interest for each month
Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -360))); //my formula
DecimalFormat twoDigits = new DecimalFormat("\$,000.00"); // declares decimal format
MIP= (Loan * Rate) / 12;
NewBal = Loan -(Payments-MIP);
System.out.println("Monthly Payments Interest Paid This Payment Loan Balance");
System.out.println();//my printout provides extra line
System.out.print("  " + twoDigits.format(Payments)); //my printout
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout
MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout

while (NewBal > 1) //while loop to make computations continue until gets to \$200000
{

MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.println("  " + twoDigits.format(Payments)); //my printout

if (NewBal <100000) // tells when this is met to transition to sleep phase

try
{
Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds
}
catch (InterruptedException e)
{
}
}
if (NewBal <1);
{
double Rate2;
Rate2 = .055; //interest rate
MonthlyInterest = Rate2 / 12; // interest for each month
Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -180))); //my formula
MIP= (Loan * Rate2) / 12;
NewBal = Loan -(Payments-MIP);
System.out.println("Monthly Payments Interest Paid This Payment Loan Balance");
System.out.println();//my printout provides extra line
System.out.print("  " + twoDigits.format(Payments)); //my printout
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout
MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout

while (NewBal > 1) //while loop to make computations continue until gets to \$200000
{

MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.println("  " + twoDigits.format(Payments)); //my printout
try
{
Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds
}
catch (InterruptedException e)
{
}
}
if (NewBal <1);
{
double Rate3;
Rate3 = .0535; //interest rate
MonthlyInterest = Rate2 / 12; // interest for each month
Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -84))); //my formula
MIP= (Loan * Rate3) / 12;
NewBal = Loan -(Payments-MIP);
System.out.println("Monthly Payments Interest Paid This Payment Loan Balance");
System.out.println();//my printout provides extra line
System.out.print("  " + twoDigits.format(Payments)); //my printout
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout
MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout

while (NewBal > 1) //while loop to make computations continue until gets to \$200000
{

MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.println("  " + twoDigits.format(Payments)); //my printout
try
{
Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds
}
catch (InterruptedException e)
{
}
}
}
}
}
}``````

All 5 Replies

You could use the scanner util class instead, possibly?

Sleep or prompt the user?

So how does this scanner util class work?

How do you use the sleep method?

How do you use the sleep method?

Hi,

this is easily found on the Java Apidocs...

(this is for 1.5. but 1.4.x behaves exactly the same)

static void sleep(long millis)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds