Explore BrainMass

Explore BrainMass

    Java Mortgage Calculator

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write a program in Java (with a graphical user interface) that calculates and displays the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:

    - 7 years at 5.35%
    - 15 years at 5.5%
    - 30 years at 5.75%

    Use an array for the mortgage data for the different loans. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection or quit.

    © BrainMass Inc. brainmass.com October 10, 2019, 2:59 am ad1c9bdddf

    Solution Preview

    Please find attached Java file Mortgage.java .

    Note, once the form opens you should enter loan amount and select a drop down term and the other fields will be populated (years, rate) automatically from the values defined in the arrays as required. You can also type in values manually if you like.

    You can run the program using Java SDK as follows.

    To compile the program:
    javac.exe -g Mortgage.java

    To run the program:
    java.exe Mortgage

    Source Code:

    // Mortgage.java

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;

    public class Mortgage extends JFrame {
    private String[] terms={"7","15","30"};
    private double[] rates={0.0535,0.055,0.0575};
    private JLabel amountLabel=new JLabel("Loan amount: ");
    private JTextField amount=new JTextField();
    private JLabel termSelLabel=new JLabel("Select Term: ");
    private JLabel termLabel=new JLabel("Years: ");
    private JTextField term=new JTextField();
    private JLabel rateLabel=new JLabel("Interest rate: ");
    private JTextField rate=new JTextField();
    private JComboBox termList = new JComboBox(terms);
    private JLabel payLabel=new JLabel("Monthly Payment: ...

    Solution Summary

    Solution contains java source code file that has been compiled and tested. A simple graphical user interface form is provided to intake the mortgage parameters such as loan amount and terms. Monthly payments and balances are calculated and displayed.