Pausing DO LOOP execution
807598Jan 19 2006 — edited Jan 19 2006Okay, I'm new to Java and taking my first Java class. I'm sure you have heard this a thousand times but I need my mortgage calculator to pause the amoritization schedule every 20 lines and wait for the user to press any key to scroll the next set. I am completly clueless how to get this done but i have managed to figure out all the other parts I need to do. What I need here is a suggestion as to how to make this thing stop every 20 lines (or 6 trips through the loop, if that is eaiser). The rest of the code seems to work pretty well but I just need a little direction for this last piece...
import java.text.*;
import java.util.Locale;
// **********CLASS DECLARATION SECTION**********
// defines the classes used in the program
public class MtgCalculator
{
static NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
// Calls the format method on the NumberFormat object
// to format the amount as desired and prints the
// results to the screen
// Found this at http://java.sun.com/developer/onlineTraining/new2java/supplements/2001/oct01.html
// Used to convert the result of the program to currency format.
static NumberFormat np = NumberFormat.getPercentInstance();
static NumberFormat ni = NumberFormat.getIntegerInstance();
public static void main(String[] args)
{
// **********VARIABLES SECTION**********
// declares the variables used by the program
double monthlyPayment;
double interest=0.0575;
double principleValue=200000.00;
int years=30;
np.setMinimumFractionDigits(2);
// **********OUTPUT SECTION**********
// provides output for the program.
System.out.println("** Mortgage Calculator **");
System.out.println("");
System.out.println(" For a " + nf.format(principleValue) + " mortgage");
System.out.println(" With a Term of " + ni.format(years) + " years");
System.out.println(" And an Interest rate of " + np.format(interest));
System.out.println(" The Payment Amount is " + nf.format(getMortgagePmt(principleValue, years, interest)) + " per month.");
System.out.println("");
System.out.println("");
double principleBalance = principleValue - ((getMortgagePmt(principleValue, years, interest)) - (principleValue*(interest/12)));
int paymentsLeft = 1;
{
do
{
double monthlyInterest = principleBalance * (interest/12);//*Current monthly interest
double monthlyPrinciple = (getMortgagePmt(principleValue, years, interest)) - monthlyInterest;//*Principal payment each month minus interest
paymentsLeft = paymentsLeft + 1;
principleBalance = principleBalance - monthlyPrinciple;//*New balance of loan
System.out.println (" Principal paid with payment " + ni.format(paymentsLeft) + " is " + nf.format(monthlyPrinciple));
System.out.println (" Interest paid with payment " + ni.format(paymentsLeft) + " is " + nf.format(monthlyInterest));
System.out.println (" New loan balance with payment " + ni.format(paymentsLeft) + " is " + nf.format(principleBalance));
System.out.println("");
} while (principleBalance > 1);
}
}
public static double getMortgagePmt(double balance, double term, double rate)
{
double monthlyRate = rate / 12;
double monthlyPayment = (balance * monthlyRate)/(1-Math.pow(1+monthlyRate, - term * 12));
return monthlyPayment;
}
}
// **********END OF PROGRAM**********