this section in the code below:
double Payment1= Math.round(loanAmount*(interestMonthly[1]/(1-Math.pow((1 + interestMonthly[1])-loanTerm[1])))*100);
Payment1=(Payment1/100);
double Payment2= Math.round(loanAmount*(interestMonthly[2]/(1-Math.pow((1 + interestMonthly[2])-loanTerm[2])))*100);
Payment2=(Payment2/100);
double Payment3= Math.round(loanAmount*(interestMonthly[3]/(1-Math.pow((1 + interestMonthly[3])-loanTerm[3])))*100);
Payment3=(Payment3/100);
//packages imported for class and method use
import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;
//class header
public class MortgageCalculatorV3
{
//method header
public static void main(String[] args)
{
DecimalFormat decimalPlace=new DecimalFormat("$000,000.00");
//Declares and builds the variables
double[] loanTerm= new double[3];
loanTerm[1]=7*12;
loanTerm[2]=15*12;
loanTerm[3]=30*12;
double[] interestMonthly=new double [3];
interestMonthly[1]=(.0535/12);
interestMonthly[2]=(.055/12);
interestMonthly[3]=(.0575/12);
double loanAmount = 200000;
double monthlyPayment = 0;
//Displays the mortgage calculator
System.out.println("Mortgage Calculator");
System.out.println("The loan amount is $200,000");
System.out.println();
//Declares and builds three new variables
double loanBalance = 0;
double interestPaid = 0;
int lineCount = 20;
loanBalance = loanAmount - monthlyPayment;
//Starts loop statement,and declares formula for loan balance and interest paid
while (loanBalance > 0) {
//Declares formula
double Payment1= Math.round(loanAmount*(interestMonthly[1]/(1-Math.pow((1 + interestMonthly[1])-loanTerm[1])))*100);
Payment1=(Payment1/100);
double Payment2= Math.round(loanAmount*(interestMonthly[2]/(1-Math.pow((1 + interestMonthly[2])-loanTerm[2])))*100);
Payment2=(Payment2/100);
double Payment3= Math.round(loanAmount*(interestMonthly[3]/(1-Math.pow((1 + interestMonthly[3])-loanTerm[3])))*100);
Payment3=(Payment3/100);
//Displays the monthly payment for each option.
System.out.println("Mortgage payment for 7 years is " + decimalPlace.format(Payment1));
System.out.println("Mortgage payment for 15 years is " + decimalPlace.format(Payment2));
System.out.println("Mortgage payment for 30 years is " + decimalPlace.format(Payment3));
loanBalance = loanBalance - monthlyPayment;
interestPaid = (monthlyPayment * interestMonthly);
//Pauses screen
if (lineCount > 0) {
lineCount--;
try {
Thread.sleep(1500);}
catch (InterruptedException e) {
}
}
}
//Stops loop statement
if (loanBalance <= 0) {
System.out.println("The loan balance is: $0.00");
}
}
}//close method header
//close class header

New Topic/Question
Reply




MultiQuote



|