This is the last part of a series of increasingly harder homework assignments, this assignment reads as:
Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:
- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%
Use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen.
This is what I have come up with, and it's obvious my logic is way off here, the if and else if statement are way off I believe.
CODE
/*
/*
Week 4: Loan Amortization Calculator
Programmer: Kevin L. Collums
Date: September 22, 2008
Filename: LoanAmort4.java
Purpose: This project will calculate the monthly loan payment for
a loan originated at $200,000.00 at 5.75% over 30 years
*/
import java.io.*;
public class LoanAmort4
{
public static void main(String[] args) throws IOException
{
//Declare variable for loan amount
double LoanAmt = 200000;
double PrincAmtOne, PrincAmtTwo, PrincAmtThree;
double PayOne, PayTwo, PayThree;// creates variable for three different payment amounts
double MonthIntOne, MonthIntTwo, MonthIntThree; //creates variables for three differene interest amounts
double MonthPrincOne, MonthPrincTwo, MonthPrincThree; //creates variables for three different principal payment amounts
PrincAmtOne = LoanAmt;
PrincAmtTwo = LoanAmt;
PrincAmtThree = LoanAmt;
MonthPrincOne = 0;
MonthPrincTwo = 0;
MonthPrincThree = 0;
MonthIntOne = 0;
MonthIntTwo = 0;
MonthIntThree = 0;
int LineCount = 1;
//create loan term array
double [] Term = {84, 180, 360};
//create interest rate array
double [] Rate = {.0535, .055, .0575};
//calculations for each payment amount
PayOne = (LoanAmt * Rate[0]) / (1-Math.pow(1+Rate[0],-Term[0]));
PayTwo = (LoanAmt * Rate[1]) / (1-Math.pow(1+Rate[1],-Term[1]));
PayThree = (LoanAmt * Rate[2]) / (1-Math.pow(1+Rate[2],-Term[2]));
//output
System.out.println("\t\tKevin's Loan Amortization Schedule");
System.out.println();
System.out.println("\t\tLoan Amount: $200,000.00");
System.out.println("\t\tTerm: 7 Years");
System.out.println("\t\tInterest Rate 5.35%");
System.out.printf("\t\tThe monthly payment amount is $%.2f", PayOne);
System.out.println();
System.out.println("\t\tTerm: 15 Years");
System.out.println("\t\tInterest Rate 5.5%");
System.out.printf("\t\tThe monthly payment amount is $%.2f", PayTwo);
System.out.println();
System.out.println("\t\tTerm: 30 Years");
System.out.println("\t\tInterest Rate 5.75%");
System.out.printf("\t\tThe monthly payment amount is $%.2f", PayThree);
System.out.println();
if (PrincAmtOne <= 0)
{
//monthly calculations for first payment amount
MonthIntOne = (PrincAmtOne * Rate[0]) / 365 * 30;
MonthPrincOne = (PayOne - MonthIntOne);
PrincAmtOne = (PrincAmtOne - MonthPrincOne);
if (PrincAmtOne <= 0)
{
//outputs
System.out.printf("Interest payment: $%.2f", MonthIntOne);
System.out.println("");
System.out.printf("Principal payment: $%.2f", MonthPrincOne);
System.out.println("");
System.out.printf("New Principal Balance: $%.2f", PrincAmtOne);
System.out.println("");
LineCount++;
}
else
{
System.out.printf("The principal balance is $0.00");
System.out.printf("");
}
else if (PrincAmtTwo <= 0)
//monthly calculations for first payment amount
MonthIntTwo = (PrincAmtTwo * Rate[0]) / 365 * 30;
MonthPrincTwo = (PayTwo - MonthIntTwo);
PrincAmtTwo = (PrincAmtTwo - MonthPrincTwo);
if (PrincAmtOne <= 0)
{
//outputs
System.out.printf("Interest payment: $%.2f", MonthIntTwo);
System.out.println("");
System.out.printf("Principal payment: $%.2f", MonthPrincTwo);
System.out.println("");
System.out.printf("New Principal Balance: $%.2f", PrincAmtTwo);
System.out.println("");
LineCount++;
}
else
{
System.out.printf("The principal balance is $0.00");
System.out.printf("");
}
else if (PrincAmtTwo <= 0)
//monthly calculations for first payment amount
MonthIntTwo = (PrincAmtTwo * Rate[0]) / 365 * 30;
MonthPrincTwo = (PayTwo - MonthIntTwo);
PrincAmtTwo = (PrincAmtTwo - MonthPrincTwo);
if (PrincAmtOne <= 0)
{
//outputs
System.out.printf("Interest payment: $%.2f", MonthIntTwo);
System.out.println("");
System.out.printf("Principal payment: $%.2f", MonthPrincTwo);
System.out.println("");
System.out.printf("New Principal Balance: $%.2f", PrincAmtTwo);
System.out.println("");
LineCount++;
}
else
{
System.out.printf("The principal balance is $0.00");
System.out.printf("");
System.exit(0);
}
}
}