Avatar of spoilerbalto
spoilerbalto

asked on 

Loop display for the Mortgage Calculator

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; */
 
 
	}
 
	 }
        	}
	}
}
}
}

Open in new window

JavaProgramming

Avatar of undefined
Last Comment
cdittberner
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of cdittberner
cdittberner
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of spoilerbalto
spoilerbalto

ASKER

Thank you very much guys, but I am still having problems when displaying the math for the following:

// Output for loan information, monthly payment, and amortization schedule
System.out.println("PaymentNo" + "/t/t" + "Payment Amount" + "/t/t" + "Loan Balance" + "/t/t" + "InterestPaid");
System.out.println(formate(paymentNo.format(i)) + " " + format(MonthlyBalance-MonthlyPrincipal)+ " " + format(monthlyPayment-monthlyPrincipal));
System.out.println("\n");
            
Is there a better way to do this than with the format's that I have written?
I am use the TextPad for my coding.                        }
Avatar of cdittberner
cdittberner
Flag of Germany image

Follow step 1 of my post and use http://www.eclipse.org instead of textpad. You will see the difference immediately.
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo