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 class MonthlyPayments3c extends Thread //class header with "Thread" for sleep
{
 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)
{
 }
}
}
}
}
}
Member Avatar for iamthwee

You could use the scanner util class instead, possibly?

Sleep or prompt the user?

BufferedReader.readLine()?

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...

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html
(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

your code can simply call
java.lang.Thread.sleep(10000);

Jason


Sunflower Network - Instant Computer Help
http://www.sunflowernetwork.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.