Purchase Solution

Alterations to a Java GUI program

Not what you're looking for?

Ask Custom Question

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

Attachments
Purchase this Solution

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.

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 ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Javscript Basics

Quiz on basics of javascript programming language.