troubleshooting Question

Loop display for the Mortgage Calculator

Avatar of spoilerbalto
spoilerbalto asked on
ProgrammingJava
4 Comments1 Solution883 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 java.io - is this line really necessary if I do not have any external imputs?

/*import java.io.*; //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);
				System.out.println();
 
	//Declares formula
	monthlyPayment = (loanAmount*(interest/12)) / (1 - 1 /Math.pow((1 + interest/12), loanTerm));
 
                    System.out.println("The monthly payment is: $" + monthlyPayment);
                    System.out.println();
 
//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) {
	lineCount--;
	for (int i=1; i <= 30*12 && (loanBalance>0); i ++)
				{
 
	//Stop each year every 12 months
	if ((i-1)%12 ==0){
 
	try
	{
	//Stops for one second
	Thread.sleep(1000);
	// 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));
						System.out.println("\n");
	}
 
	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; */
 
 
	}
 
	 }
        	}
	}
}
}
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros