I am not sure how to fix this problem. I am trying to pause the display after the first 15 lines until the array ends.

``````/*  Week 4 Individual
*   Programmer: Melissa Snider
*   Date: 4/6/2008
*   Calculate the mortgage payment for 3 loans with an array
*/

package prg420.week4;                   // adds the package
import java.text.DecimalFormat;           // Import the java. text for formating
import java.lang.Math;          //Import the java math

class Calculator //creates and start this class
{

public void MortArray()                   //creates array
{
java.text.DecimalFormat df2 = new java.text.DecimalFormat(",###.00");  // formats numbers to display only two decimal places

// declare variables
double monPayment;       // monthly payment
double monIntRate;   // monthly interest rate
int months;      // length of loan in months

double[][] mortgage =

{{200000, 84, 5.35, 0.0},
{200000, 180, 5.50, 0.0},
{200000, 360, 5.75, 0.0}};

//Using an array

for(int i=0; i<3; i++)                         // starts loop
{
months = (int) mortgage[i][1];
monIntRate = (mortgage[i][2]/12)/100;
monPayment = (mortgage[i][0]*monIntRate)/(1-Math.pow(1+monIntRate, -months));

System.out.println ("\n\nMortgage amount is \t" + df2.format(mortgage[i][0]));
System.out.println ("Terms of mortgage is \t " + mortgage[i][1] + "months");
System.out.println ("Interest rate is \t " + mortgage[i][2] + "%");
System.out.println ("Monthly mortgage payment \t\$" + df2.format(monPayment));
}
}
}

public class MortCalculator
{
public static void main( String args[] )    //Create main method
{
Calculator  CalculatorA = new Calculator(); //Create object with instance of MCalc

CalculatorA.MortArray();      //Call array

// these conditional statements cause the results to pause
if(term == 15)
{
term = 0;
try
{
Thread.sleep(5000);     // pause to last five seconds
catch (InterruptedException e)
{
}
}   // end if
else
{
term++;
}   // end else

}
}
``````

Help

Edited by Reverend Jim: Fixed formatting

2
Contributors
7
Replies
8
Views
10 Years
Discussion Span
Last Post by Ezzaral

When I compile, I get 3 errors on the word term cannot find symbol? Do I need to define term in the main method also?

Having the sleep() in main() after you have called the mortArray() method will not cause your output to pause. The loop will continue to run until complete and then return to execute the rest of your code in main() - which is your pause code.

You need to place the sleep() code into the mortArray() method inside the loop that is generating the output.

I changed the code to this and now it compiles but no display. Where did I go wrong?

``````package prg420.week5;                   // adds the package
import java.text.DecimalFormat;           // Import the java. text for formating
import java.lang.Math;          //Import the java math

class Calculator //creates and start this class
{

public void MortArray()                   //creates array
{
java.text.DecimalFormat df2 = new java.text.DecimalFormat(",###.00");  // formats numbers to display only two decimal places

// declare variables
double monPayment;       // monthly payment
double monIntRate;   // monthly interest rate
int months;      // length of loan in months

double[][] mortgage =

{{200000, 84, 5.35, 0.0},
{200000, 180, 5.50, 0.0},
{200000, 360, 5.75, 0.0}};

//Using an array

for(int i=0; i<3; i++)                         // starts loop
{
for (months<360); months++)
months = (int) mortgage[i][1];
monIntRate = (mortgage[i][2]/12)/100;
monPayment = (mortgage[i][0]*monIntRate)/(1-Math.pow(1+monIntRate, -months));

System.out.println ("\n\nMortgage amount is \t" + df2.format(mortgage[i][0]));
System.out.println ("Terms of mortgage is \t " + mortgage[i][1] + "months");
System.out.println ("Interest rate is \t " + mortgage[i][2] + "%");
System.out.println ("Monthly mortgage payment \t\$" + df2.format(monPayment));
int count=0;
// these conditional statements cause the results to pause
if(count == 15)
{
count = 0;
try
{
Thread.sleep(5000);     // pause to last five seconds
catch (InterruptedException e)
{
}
}   // end if
else
{
count++;
}   // end else
}
}
}

public class MortCalculator
{
public static void main( String args[] )    //Create main method
{
Calculator  CalculatorA = new Calculator(); //Create object with instance of MCalc

CalculatorA.MortArray();      //Call array

}
}
``````

thanks

Edited by mike_2000_17: Fixed formatting

No, it does not compile. This portion here is undecipherable

``````for(int i=0; i<3; i++) // starts loop
{
for (months<360); months++)``````

Also, the end code tag needs to be [/code] for the code to be formatted correctly.

I now have one error. How do I need to fix it?

``````package prg420.week5;                   // adds the package
import java.text.DecimalFormat;           // Import the java. text for formating
import java.lang.Math;          //Import the java math

class Calculator //creates and start this class
{
public class months<i> {

public void add (i[B]) ; {[/B]
this.i = i;
}

public i get() {
return i;
}
}

public void MortArray()                   //creates array
{
java.text.DecimalFormat df2 = new java.text.DecimalFormat(",###.00");  // formats numbers to display only two decimal places

// declare variables
double monPayment [] = new double [3] ;       // monthly payment
double monIntRate [] = new double [2] ;       // monthly interest rate
int months[] = new int [1] ;             // length of loan in months

double[][] mortgage =

{{200000, 84, 5.35, 0.0},
{200000, 180, 5.50, 0.0},
{200000, 360, 5.75, 0.0}};

//Using an array
months = months[1];
monIntRate = (mortgage[i][2]/12)/100;
monPayment = (mortgage[i][0]*monIntRate)/(1-Math.pow(1+monIntRate, -months));

System.out.println ("\n\nMortgage amount is \t" + df2.format(mortgage[i][0]));
System.out.println ("Terms of mortgage is \t " + mortgage[i][1] + "months");
System.out.println ("Interest rate is \t " + mortgage[i][2] + "%");
System.out.println ("Monthly mortgage payment \t\$" + df2.format(monPayment));

if(months == 1){
System.out.println("\n\n\nPayment\t\tPrincipal\t\tInterest\tPrincipal");
System.out.println("Month #\t\tPayment\t\t\tPayment\t\tBalance");
System.out.println("-------  \t---------\t\t---------\t---------");
}
System.out.println();
System.out.println(months+ "\t\t\$" + df2.format(monPayment) +
" \t\t\$" + df2.format(monthlyIntPay) +
"\t\t\$" + df2.format(balance));

{
System.out.print("\nPress Enter To Continue showing payments for for Loan No. " + (i+1)+":");
byte[] buffer = new byte[12];
counter = 0;
if(months[i]){
System.out.println("\n\n\nMonths\t\tPrincipal\t\tInterest\tPrincipal");
System.out.println("\t\tPayment\t\t\tPayment\t\tBalance");
System.out.println("---------\t---------\t\t---------\t---------");

for(int i=0; i<3; i++)                         // starts loop
{for (int count = 1; count < 360; count ++)
{
if (count == 15)
break;
};

System.out.println ("\n\nMortgage amount is \t" + df2.format(mortgage[i][0]));
System.out.println ("Terms of mortgage is \t " + mortgage[i][1] + "months");
System.out.println ("Interest rate is \t " + mortgage[i][2] + "%");
System.out.println ("Monthly mortgage payment \t\$" + df2.format(monPayment));
}
}
}
}
public class MortCalculator
{
public static void main( String args[] )    //Create main method
{
Calculator  CalculatorA = new Calculator(); //Create object with instance of MCalc

CalculatorA.MortArray();      //Call array
int count=0;
// these conditional statements cause the results to pause
if(count == 15)
{
count = 0;
try
{
Thread.sleep(5000);		// pause to last five seconds
catch (InterruptedException e)
{
}
}	// end if
else
{
count++;
}	// end else
}
}
}``````

the bold is where the error is located when compiling.
public void add (i) ; {

It's an invalid method signature. You have no type for the parameter and you have a semi-colon between the parameter list and the brace that begins the block.

Also, this piece of code is not doing anything useful at all

``````for (int count = 1; count < 360; count ++)
{
if (count == 15)
break;
};``````

It just counts from 1 to 15 - nothing more.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.