Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please assist by running the following source code on Apache NetBeans IDE 2 1 or any Java programming language. While testing, please capture and submit
Please assist by running the following source code on Apache NetBeans IDE or any Java programming language. While testing, please capture and submit screenshots.
public class LoanCalculator extends JFrame
private JTextField loanAmountField, interestRateField, termField;
private JLabel monthlyPaymentLabel;
private JButton calculateButton, resetButton;
public LoanCalculator
createView;
setTitleLoan Calculator";
setDefaultCloseOperationEXITONCLOSE;
setSize;
setLocationRelativeTonull;
setResizablefalse;
private void createView
JPanel panel new JPanelnew GridBagLayout;
getContentPaneaddpanel;
GridBagConstraints c new GridBagConstraints;
cfill GridBagConstraints.HORIZONTAL;
Loan Amount
JLabel loanAmountLabel new JLabelLoan Amount R:;
cgridx ;
cgridy ;
panel.addloanAmountLabel c;
loanAmountField new JTextField;
cgridx ;
cgridy ;
panel.addloanAmountField c;
Interest Rate
JLabel interestRateLabel new JLabelAnnual Interest Rate :;
cgridx ;
cgridy ;
panel.addinterestRateLabel c;
interestRateField new JTextField;
cgridx ;
cgridy ;
panel.addinterestRateField c;
Loan Term
JLabel termLabel new JLabelLoan Term years:;
cgridx ;
cgridy ;
panel.addtermLabel c;
termField new JTextField;
cgridx ;
cgridy ;
panel.addtermField c;
Calculate Button
calculateButton new JButtonCalculate;
cgridx ;
cgridy ;
cgridwidth ;
panel.addcalculateButton c;
calculateButton.addActionListenernew ActionListener
public void actionPerformedActionEvent e
calculateMonthlyPayment;
;
Monthly Payment Display
monthlyPaymentLabel new JLabelMonthly Payment: ;
cgridx ;
cgridy ;
cgridwidth ;
panel.addmonthlyPaymentLabel c;
Reset Button
resetButton new JButtonReset;
cgridx ;
cgridy ;
cgridwidth ;
panel.addresetButton c;
resetButton.addActionListenernew ActionListener
public void actionPerformedActionEvent e
resetFields;
;
private void calculateMonthlyPayment
double principal Double.parseDoubleloanAmountFieldgetText;
double annualInterestRate Double.parseDoubleinterestRateFieldgetText;
int termYears Integer.parseInttermFieldgetText;
double monthlyInterestRate annualInterestRate ;
int totalPayments termYears ;
$$
M P r rn rn
$$
where:
M monthly payment
P principal loan amount
r monthly interest rate
n number of payments
double monthlyPayment principal monthlyInterestRate Math.pow monthlyInterestRate, totalPaymentsMathpow monthlyInterestRate, totalPayments;
monthlyPaymentLabel.setTextMonthly Payment: R String.formatf monthlyPayment;
private void resetFields
loanAmountField.setText;
interestRateField.setText;
termField.setText;
monthlyPaymentLabel.setTextMonthly Payment: ;
public static void mainString args
SwingUtilities.invokeLaternew Runnable
public void run
new LoanCalculatorsetVisibletrue;
;
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