troubleshooting Question

Loop display for the Mortgage Calculator

Avatar of spoilerbalto
spoilerbalto asked on
4 Comments2 Solutions883 ViewsLast Modified:
I am having some problems with one line of my code.
It is the format line which populates my list information.
I also had to comment out import - is this line really necessary if I do not have any external imputs?

/*import*; //Java input and output */
import java.math.*; //This is so I can do math in my program
import java.text.DecimalFormat; //This is so I can use text and decimals in my program
public class MortgageCalculator //Name program is saved under and class
public static void main(String[] args){
//Declares and builds the variables
			int loanAmount = 200000;
			int loanTerm = 360;
			double interest = .0575;
			double monthlyPayment = interest/12;
			double loanBalance = 0;
			double intrestPaid = 0;
			double paymentNo = 0;
			double downPayment = 20000;
			double intrestMonthly = 0;
			double interestPaid = 0;
	//Displays the mortgage calculator data
               System.out.println("*******This is Kelly's Mortgage Calculator*******");
                System.out.println("\nThe Mortgage Priciple is:" + loanAmount);
                System.out.println("\nThe down payment is: " + downPayment);
                System.out.println("\nThe years for this loan is: " + loanTerm);
                System.out.println("\nThe intrest rate is: " + interest);
	//Declares formula
	monthlyPayment = (loanAmount*(interest/12)) / (1 - 1 /Math.pow((1 + interest/12), loanTerm));
                    System.out.println("The monthly payment is: $" + monthlyPayment);
//Declares and builds three new variables
		int lineCount = 20;
		loanBalance = loanAmount - monthlyPayment;
	//Starts loop statement,and declares formula for loan balance and interest paid
		while (loanBalance > 0){
	//Displays the loan balance and interest paid
                     System.out.println("The loan balance is: $" + loanBalance);
	System.out.println("The interest paid on the loan is: $" + interestPaid);
	//Pauses screen
	if (lineCount >0) {
	for (int i=1; i <= 30*12 && (loanBalance>0); i ++)
	//Stop each year every 12 months
	if ((i-1)%12 ==0){
	//Stops for one second
	// Output for loan information, monthly payment, and amortization schedule of payments
	 System.out.println("Payment No" + "/t/t" + "Payment Amount" + "/t/t" + "Loan Balance" + "/t/t" + "Interest Paid");
**************Problem Area - I think *******************				System.out.println(format(paymentNo.format(i)) + " " + format(MonthlyBalance-MonthlyPrincipal)+ " " + format(monthlyPayment-monthlyPrincipal));
	catch (Exception e)
						/*System.out.println(formate(paymentNo.format(i)) + /t/t + format(loanBalance
	formatter.format(paymentNo) + \t + formatter.format(loanBalance -=principalPaid;
                              interestPaid = loanBalance*monthlyInterestRate;principalPaid = payment -                              interestPaid; */

Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 4 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004