Mortgagecalc W3

Submitted by: Submitted by

Views: 376

Words: 394

Pages: 2

Category: Science and Technology

Date Submitted: 05/30/2008 07:00 PM

Report This Essay

// Import IO Libraries

import java.io.*;

// MortgageCalc_W3 Class - Main Program

public class MortgageCalc_W3

{

// Main Method

public static void main(String[] args) throws IOException

{

// Program Assumptions

// Loan 1 - 7 year at 5.35%

// Loan 2 - 15 year at 5.5%

// Loan 3 - 30 year at 5.75%

// Loan Amount is $200,000.00

// Simple Error check for selection

boolean breakout = false;

double loan_amount = 200000.00,

months = 12,

total_payments;

double[] apr = { 0.0535, 0.055, 0.0575 },

year = { 7, 15, 30 };

int t,

response = 0;

BufferedReader choices = new BufferedReader(new

InputStreamReader(System.in));

// Choice - Which Loan will be calculated?

while (breakout != true)

{

// Loop through the Arrays to show Loan Options

for (t = 0; t <= 2; t++)

{

System.out.println((t+1) +" - Loan at " + (apr[t]*100) + "% for " +

year[t] + " years.");

}

// Loan choice 1 - 3

System.out.printf("Enter your choice (1-3): ");

response = Integer.parseInt(choices.readLine());

// Verify choice, if true breakout of loop

if (response > 0 && response < 4)

breakout = true;

else

System.out.println("Sorry, your selection was not 1 - 3. Try Again!");

}

// Print Choice and details

System.out.println("You chose option #" + response + " with an APR of " + (apr[response - 1] * 100) + "%.");

// Calculate total payments based on loan choice

total_payments = (year[response - 1] * months);

// Calculate loan with interest and display

loancalc(loan_amount,apr[response - 1],total_payments,months);

}

// loancalc method - calculate loan and display

public static void loancalc(double loan_amount,double apr,double

total_payments,double months) throws IOException

{

// loan calc required variables

double principle = loan_amount,

interest = 0,

total_interest = 0,

total_loan_cost = 0,

total_loan_cost2,

payment;

double fractional_apr = (apr / months);

int i = 0,

line_no = 0;

// Calculate Payments, total_interest,...