Question
I need help with exercise 16-1 Modify the Future Value application from the book murach's java programming 4th edition. The directions for this excercise are
I need help with exercise 16-1 "Modify the Future Value application" from the book murach's java programming 4th edition. The directions for this excercise are as follows:
1. Open the project named ch16_ex1_FutureValue in the ex_starts directory. Then, review the design and code for the form.
(below is the exact code given to me to start)
package murach.ui;
import java.text.NumberFormat; import murach.business.FinancialCalculations;
public class FutureValueFrame extends javax.swing.JFrame {
/** Creates new form FutureValueFrame */ public FutureValueFrame() { initComponents(); }
/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") //
jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); monthlyPaymentTextField = new javax.swing.JTextField(); yearlyRateTextField = new javax.swing.JTextField(); yearsTextField = new javax.swing.JTextField(); futureValueTextField = new javax.swing.JTextField(); calculateButton = new javax.swing.JButton(); exitButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Future Value Calculator"); setResizable(false);
jLabel1.setText("Monthly Payment:");
jLabel2.setText("Yearly Interest Rate:");
jLabel3.setText("Number of Years:");
jLabel4.setText("Future Value:");
futureValueTextField.setEditable(false); futureValueTextField.setFocusable(false);
calculateButton.setMnemonic('c'); calculateButton.setText("Calculate"); calculateButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { calculateButtonActionPerformed(evt); } });
exitButton.setMnemonic('x'); exitButton.setText("Exit"); exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } });
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4)) .addGap(16, 16, 16) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(futureValueTextField) .addComponent(yearsTextField) .addComponent(yearlyRateTextField) .addComponent(monthlyPaymentTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(calculateButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(exitButton))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(monthlyPaymentTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(yearlyRateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(yearsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(futureValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(exitButton) .addComponent(calculateButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) );
pack(); }// //GEN-END:initComponents
private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateButtonActionPerformed if (isValidData()) { double p = Double.parseDouble(monthlyPaymentTextField.getText()); double r = Double.parseDouble(yearlyRateTextField.getText()); int y = Integer.parseInt(yearsTextField.getText()); double fv = FinancialCalculations.calculateFutureValue(p, r, y); NumberFormat currency = NumberFormat.getCurrencyInstance(); futureValueTextField.setText(currency.format(fv)); } }//GEN-LAST:event_calculateButtonActionPerformed
private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed System.exit(0); }//GEN-LAST:event_exitButtonActionPerformed
private boolean isValidData() { SwingValidator sv = new SwingValidator(); return sv.isPresent(monthlyPaymentTextField, "Monthly Investment") && sv.isDouble(monthlyPaymentTextField, "Monthly Investment") && sv.isPresent(yearlyRateTextField, "Interest Rate") && sv.isDouble(yearlyRateTextField, "Interest Rate") && sv.isPresent(yearsTextField, "Number of Years") && sv.isInteger(yearsTextField, "Number of Years"); }
/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // new FutureValueFrame().setVisible(true); // generated code FutureValueFrame frame = new FutureValueFrame(); frame.setVisible(true); frame.setLocationRelativeTo(null); } }); }
// Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton calculateButton; private javax.swing.JButton exitButton; private javax.swing.JTextField futureValueTextField; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JTextField monthlyPaymentTextField; private javax.swing.JTextField yearlyRateTextField; private javax.swing.JTextField yearsTextField; // End of variables declaration//GEN-END:variables
}
The next steps are as follows:
2. Replace the Number of Years text field with a combo box. Then, code a method that fills this combo box with the values 1 through 20, and call this method from the constructor for the frame. Make any other necessary changes to provide for the combo box. Test the project to be sure in works correctly.
3. Replace the future value text field with a list that displays five rows and uses a vertical scroll bar but no horizontal scroll bar.
4. Modify the actionPerformed event for the Calculate button so that instead of calculating a single value, it calculates the future value for each year up to the year selected via the combo box and adds a string showing the calculation for each year to the list.
5. Test the project to make sure it works correctly.
If you need more code, please let me know. when it's finished it should look like this:
interface should look something like this: Future Value Calculator Monthly Payment: 100 Yearly Interest Rate: 5 Number of YearS: Future Value: Year 1: $1,233.00 Year 2: $2,529.09 Year 3: $3,891.48 Year 4: $5,323.58 Calculate ExitStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started