Question
This from Murach exercise 16-1 on Page 534 Number of Years text field replaced with combobox Future Value text field replaced with a list having
This from Murach exercise 16-1 on Page 534
Number of Years text field replaced with combobox
Future Value text field replaced with a list having a vertical scrollbar
Calculate button event listener calculates the future values for each year selected in the combobox
Calculate button event listener displays the calculated the future values for each year selected in the list
_____________________
These are the Forms gives
murach.business>FinancialCalculations.java
package murach.business;
public class FinancialCalculations { public static final int MONTHS_IN_YEAR = 12;
public static double calculateFutureValue(double monthlyPayment, double yearlyInterestRate, int years) { int months = years * MONTHS_IN_YEAR; double monthlyInterestRate = yearlyInterestRate/MONTHS_IN_YEAR/100; double futureValue = 0; for (int i = 1; i <= months; i++) { futureValue = (futureValue + monthlyPayment) * (1 + monthlyInterestRate); } return futureValue; } }
murach.ui>SwingValidator.java
package murach.ui;
import javax.swing.*; import javax.swing.text.JTextComponent;
public class SwingValidator { public boolean isPresent(JTextComponent c, String fieldName) { if (c.getText().length() == 0) { showMessage(c, fieldName + " is a required field."); c.requestFocusInWindow(); return false; } return true; }
public boolean isInteger(JTextComponent c, String fieldName) { try { int i = Integer.parseInt(c.getText()); return true; } catch (NumberFormatException e) { showMessage(c, fieldName + " must be an integer."); c.requestFocusInWindow(); return false; } }
public boolean isDouble(JTextComponent c, String fieldName) { try { double d = Double.parseDouble(c.getText()); return true; } catch (NumberFormatException e) { showMessage(c, fieldName + " must be a valid number."); c.requestFocusInWindow(); return false; } }
private void showMessage(JTextComponent c, String message) { JOptionPane.showMessageDialog(c, message, "Invalid Entry", JOptionPane.ERROR_MESSAGE); } }
____________________________
Thank you.
Step 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