Java GUI Loan Calculator~10 pts today!?
I have everything working correctly except for my totalMonthlyPaymentField output. I am pasting only partial code (about 500 lines in total for the entire project), but pay particular attention to the method:
private void monthlyPaymentButtonActionPerformed
This is where I believe my issue is. I am thinking I need to add a num4, but am struggling as to where; for everywhere I have added it thus far has not worked.
Any suggestions or helping comments are greatly appreciated and I thank you in advance! Remember, 10 pts!
p.s. if this is not good enough, and if you need more code, send me an email and I will send you the entire project. Thanks!
package my.CarLoan;
public class CarLoanUI extends javax.swing.JFrame {
/** Creates new form CarLoanUI */
public CarLoanUI() {
initComponents();
}
//Declaration of variables
float num1, num2, num3, num4;
private void toBeFinancedButtonActionPerformed(java.awt.event.ActionEvent evt) {
num1 = Float.parseFloat(CarPriceField.getText());
num2 = Float.parseFloat(DownPymtField.getText());
num3 = num1 – num2;
totalFinancedField.setText(String.format("$%,.2f",num3));
}
private void totalAfterFinancingButtonActionPerformed(java.awt.event.ActionEvent evt) {
//need to make a num4 here
totalFinancedField.getText() ;//&& buttonGroup1
if (RatingPoorButton.isSelected())
totalAfterFinancedField.setText(String.format("$%,.2f",num3 * .12 + num3 ));
else
if (RatingAverageButton.isSelected())
totalAfterFinancedField.setText(String.format("$%,.2f",num3 * .10 + num3 ));
else
if (RatingGreatButton.isSelected())
totalAfterFinancedField.setText(String.format("$%,.2f",num3 * .05 + num3 ));
}
private void monthlyPaymentButtonActionPerformed(java.awt.event.ActionEvent evt) {
totalAfterFinancedField.getText();
if (Button12Months.isSelected())
totalMonthlyPaymentField.setText(String.format("$%,.2f",num4 / 12 ));
else
if (Button24Months.isSelected())
totalMonthlyPaymentField.setText(String.format("$%,.2f",num4 / 24 ));
else
if (Button36Months.isSelected())
totalMonthlyPaymentField.setText(String.format("$%,.2f",num4 / 36 ));
}
I will be posting for the correct answer in an hour or so. Thanks a million for both of you for taking the time to get to a solution! The best part about this is..I was able to get the correct syntax just before I received your answers
. Weeeeeee!!
Thanks again!
I can work on this with you VIA email.
My email is: irishtek@yahoo.com
Can you please send me in the email the monthlyPaymentButtonActionPerformed method and the issue you are having with the output.
The question posted has some elements left out with …. that make it difficult to know what I am looking at.
Okay I think I have found your problem
In these lines of code:
if (Button12Months.isSelected()) totalMonthlyPaymentField.setText(String.format("$%,.2f",num4 / 12 ));
elseif (Button24Months.isSelected()) totalMonthlyPaymentField.setText(String.format("$%,.2f",num4 / 24 ));
elseif (Button36Months.isSelected()) totalMonthlyPaymentField.setText(String.format("$%,.2f",num4 / 36 ));
num4 has no value and will default to 0this line:
num4 = Float.parseFloat(totalAfterFinancedField.getText());
should be uncommented and moved above your if statements so that num4 is properly assigned before it is used.
Let me know if this helps or if you need more assistance on this problem.