asked on
/*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; */
}
}
}
}
}
}
}
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.
TRUSTED BY
ASKER
// Output for loan information, monthly payment, and amortization schedule
System.out.println("Paymen
System.out.println(formate
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. }