Explore BrainMass
Share

Explore BrainMass

    Alterations to a Java GUI program

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

    Remove drop down box 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%

    Have it only calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. Allow the user to loop back and enter new data or quit. Please insert comments in the program to document the program. Attach a design flow chart to the source code of the program.

    See below for the program:

    import java.io.*; import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.text.*; import java.util.*; public class Dmortgage2 extends JApplet { private String[] terms={"7","15","30"}; private double[] rates={0.0535,0.055,0.0575}; private JLabel amountLabel=new JLabel("
    Loan amount (Please enter a loan amount):
    " , JLabel.CENTER); private JTextField amount=new JTextField(); private JLabel termLabel=new JLabel("
    Enter your own terms or select a term from the drop down box for 7 Years at 5.35%, 15 Years at 5.50%, 30 Years at 5.75% .
    ", JLabel.RIGHT); private JTextField term=new JTextField(); private JLabel rateLabel=new JLabel("nn Interest rate : " , JLabel.CENTER); private JTextField rate=new JTextField(); private JComboBox termList = new JComboBox(terms); private JLabel payLabel=new JLabel("Click Calculate when all the fields are filled in
    for the Monthly Payment : ", JLabel.CENTER); private JLabel payment=new JLabel(); private JButton calculate=new JButton("Calculate"); private JButton clear=new JButton("Clear"); private JButton exit=new JButton("Exit"); private JTextArea paymentSchedule=new JTextArea(); private JScrollPane schedulePane=new JScrollPane(paymentSchedule); private Container cp = getContentPane(); public void init() { // Take care of termList termList.setSelectedIndex(0); termList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox)e.getSource(); // the source of the event is the combo box String termYear = (String)cb.getSelectedItem(); term.setText(termYear); int index=0; switch (Integer.parseInt(termYear)) { case 7: index=0; break; case 15: index=1; break; case 30: index=2; break; } rate.setText(rates[index]+""); } }); // Take care of three buttons calculate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // calculate the monthly payment double p=Double.parseDouble(amount.getText()); double r=Double.parseDouble(rate.getText())/12; double n=Integer.parseInt(term.getText())*12; double monthlyPayment=p*Math.pow(1+r,n)*r/(Math.pow(1+r,n)-1); DecimalFormat df = new DecimalFormat("$###,###.00"); payment.setText(df.format(monthlyPayment)); // calculate the detailed loan double principal=p; int month; StringBuffer buffer=new StringBuffer(); buffer.append("MonthtAmounttInteresttBalancen"); for (int i=0; i

    © BrainMass Inc. brainmass.com October 9, 2019, 10:22 pm ad1c9bdddf
    https://brainmass.com/computer-science/java/alterations-to-a-java-gui-program-217906

    Attachments

    Solution Preview

    The drop-down feature was being created by the JComboBox element. In
    order to get rid of this from the GUI it is necessary ...

    Solution Summary

    This solution shows how to make alterations to a Java GUI application. The modification is attached in a .java file and a flow chart is included in a PDF file.

    $2.19