Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the program in Java (with a graphical user interface) and have it calculat

ID: 3638678 • Letter: W

Question

Write the program in Java (with a graphical user interface) and have it calculate and display 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. Read the interest rates to fill the array from a sequential file. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Add graphics in the form of a chart. Allow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program.

Explanation / Answer

import java.awt.*; //to create buttons, etc w/o actions import java.awt.event.*; //to create an event or action import javax.swing.*; import javax.swing.JButton; //to create a button import javax.swing.JTextField; //to create a text field import java.text.DecimalFormat; //to import decimal format for money //Class public class MortgageText extends JPanel implements ActionListener { //Global Variable protected JComboBox MortCombo; protected JLabel lblprincipal, lblinterestRate, lblTerm, lblmonthlyPayment; protected JButton calculate, Clear; protected JTextField principal, interestRate, Term, monthlyPayment; protected TextArea MortTextField; public MortgageText() { String[] comboItems={"5.35","5.50","5.75","10.0"}; //creates labels and fields lblprincipal=new JLabel("Principal Amount:"); principal = new JTextField("",10); lblinterestRate=new JLabel("Interest Rate:"); interestRate = new JTextField("",10); lblTerm=new JLabel("Term:"); Term = new JTextField("",10); lblmonthlyPayment=new JLabel("Monthly Payment:"); monthlyPayment = new JTextField("",10); MortCombo=new JComboBox(comboItems); MortTextField=new TextArea(10,120); //create buttons calculate = new JButton("Calculate"); //button used to calculate mortgage payment calculate.setActionCommand("GO"); Clear = new JButton("Clear"); //button used to clear data from the fields Clear.setActionCommand("Clear"); //add action to button calculate.addActionListener(this); Clear.addActionListener(this); add(lblprincipal); add(principal); add(lblinterestRate); add(MortCombo); add(lblTerm); add(Term); add(lblmonthlyPayment); add(monthlyPayment); add(calculate); add(Clear); add(MortTextField); } public void actionPerformed(ActionEvent e) { if ("GO".equals(e.getActionCommand())) { CalculateMortgage(); } else { principal.setText(""); interestRate.setText(""); Term.setText(""); monthlyPayment.setText(""); } } // principal.setText(interestRate.getText()); --this will read the interestRate text field and copy it to the principal field public void CalculateMortgage() { double dblprincipal=Double.parseDouble(principal.getText()); double dblinterestRate=Double.parseDouble((String)MortCombo.getSelectedItem()); int intTerm=Integer.parseInt(Term.getText()); DecimalFormat money = new DecimalFormat("$0.00"); double MonthlyPayment=0.0; double InterestPayment=0.0; double PrincipalBal=0.0; double MIntRate=dblinterestRate/1200; int MTerms=intTerm * 12; //monthly payment formula MonthlyPayment=(dblprincipal * MIntRate) / (1-Math.pow((MIntRate+1),-MTerms)); //converts Monthly Payment to decimal format monthlyPayment.setText("" + (money.format(MonthlyPayment))); MortTextField.append("Month No. Monthly Payment Loan Balance Interest Payment "); MortTextField.append("1 " + MonthlyPayment + PrincipalBal + InterestPayment + " "); //REMOVE "FOR" STATEMENT FOR WEEK 5 HOMEWORK for (int counter=1; counter