MortgageCalculator

java

School

Fayetteville State University *

*We aren’t endorsed by this school

Course

MISC

Subject

Computer Science

Date

Nov 24, 2024

Type

java

Pages

2

Uploaded by HeavyA

Report
import java.util.Scanner; public class MortgageCalculator { public static void main(String[] args) { // Declares and sets the scanner variable Scanner scan = new Scanner(System.in); // Declares the property tax rate constant final double PROPERTY_TAX_RATE = 1.5; // Declares the inputted variables String address; int zipCode; int noOfYears; double offerPri; double downPayPercent; double annInterestRate; // Declares the calculation varaibles to output double totDownPayment; double loanAmt; int maturityYr; String maturityDate; double mthIntrestRate; double mthMortPay; double mthPropTax; double totMthPay; double totPayment; // Prompts the user with the loan information System.out.print("Enter property zip code: "); zipCode = scan.nextInt(); scan.nextLine(); // clear the input buffer System.out.print("Enter property address: "); address = scan.nextLine(); System.out.print("Enter property offer price: $"); offerPri = scan.nextDouble(); System.out.print("Enter down payment (in percentage %): "); downPayPercent = scan.nextDouble(); System.out.print("Enter number of years financing: "); noOfYears = scan.nextInt(); System.out.print("Enter annual interest rate (in percentage %): "); annInterestRate = scan.nextDouble(); // simulate delay due to calculation System.out.println("Mortgage calculator is processing your data... Please wait..."); try { Thread.sleep(3000); } catch (Exception e) { e.printStackTrace(); } // Performing calculations for the loan totDownPayment = offerPri * downPayPercent / 100; loanAmt = offerPri - totDownPayment;
maturityYr = 2023 + noOfYears; maturityDate = "12/31/" + maturityYr; mthIntrestRate = annInterestRate / 1200; mthMortPay = loanAmt * mthIntrestRate / (1 - 1 / Math.pow(1 + mthIntrestRate, noOfYears * 12)); mthPropTax = offerPri * PROPERTY_TAX_RATE / 100 / 12; totMthPay = mthMortPay + mthPropTax; totPayment = mthMortPay * 12 * noOfYears; // Output the information about the loan System.out.println (" ***************************************"); System.out.println (" \tMORTGAGE CALCULATOR RESULTS"); System.out.println (" ***************************************"); System.out.println ("Property address: "+ address +" "+zipCode); System.out.printf ("Property offer price: \t\t\t\t$ %.2f", offerPri); System.out.printf ("\nTotal down payment: \t\t\t\t$ %.2f", totDownPayment); System.out.printf ("\nLoan amount: \t\t\t\t\t$ %.2f", loanAmt); System.out.println("\nLoan maturity date: \t\t\t " + maturityDate); System.out.printf ("Monthly mortgage payment: \t\t\t$ %.2f", mthMortPay); System.out.printf ("\nTotal monthly payment (property tax included): $ %.2f", totMthPay); System.out.printf ("\nTotal payment (excluding tax): \t\t\t$ %.2f",totPayment); System.out.println(); } }
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help