Need help with creating a loop
Hi. I am trying to create a loop to allow user to enter data and present data or allow user to exit. I created a loop but this goes through the information continuously. I need the user to enter mortgage amount, interest rate, and loan term. The program should calculate and output data. The program should allow the user to enter new amounts or exit. I am sure I am missing something little, but I am not sure. Could someone lead me the right way? Thanks. Here is the code.
Code:
package mortgage;
/**The Mortgage class implements an application which calculates the mortgage
*payment, interest paid, principal paid and loan balance.
* The application prints interest paid, mortgage payment, and loan balance
* to output
* @author Lekeisha
**/
import java.util.Scanner;
public class Mortgage
/**Creates a new instance of Mortgage**/
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
do{
System.out.print("Enter amount of mortgage: ");
double amLoanOne = scan.nextDouble();//get amount of mortgage from user
System.out.print("Enter loan term: ");
double loanTerm = scan.nextDouble();//get value for loan term from user
System.out.print("Enter interest rate: ");
double intRates = scan.nextDouble();//get interest rate from user
double monIntRate = 0.0;//initiates the monthly interest rate
double monPay = 0;//initiates the mortgage payment
double intsPaid = 0;//initiates interest paid
double princPaid = 0;//initiates principal paid
monIntRate = intRates/12;//interest rate of 5.35% divided by 12 months equals the monthly interest rate
double totMons = loanTerm*12;//term of loan multiplied by 12 months equals total months of term
double amLoanNxt = amLoanOne;//initiates the amount of loan balance after initial amount
monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
//calculates the mortgage payment
intsPaid = amLoanOne*monIntRate;
//calculates the interest paid
princPaid = monPay - intsPaid;
//calculates the principal paid
amLoanNxt = amLoanOne - princPaid;
//calculates the amount of loan balance after initial amount
System.out.println("Interest amount is $" + Math.round(intsPaid)+ ".");
//calculates the interest paid with interest rate of 5.75%
System.out.println("Mortgage payment amount is $" + Math.round(monPay)+ ".");
//calculates the mortgage payment amount
System.out.println("Loan balance amount is $" + Math.round(amLoanNxt)+ ".");
//calculates the loan balance
System.out.println("(press 0 to exit)");
//asks user input of 'Enter' to display other lines of text
}
while (amLoanOne != '0');
}
}