Hi, I've been having trouble with my loan calculator applet code. I basically have to write a Java applet program (together with its html test file) to calculate loan payments. The user will provide the interest rate, the number of years, and loan amount
this is what I have so far
The error I keep getting here is at line 71 (Loan loan = new Loan(interest, year, loanAmount); that java cannot find symbol and it points to where Loan is after new.
I've tried adding in a NoClassDefErrorException import and that didn't work. I tried changing the name of the code and that didn't work either. I've even tried adding a public class loan in the main method but I realized then that a class can't be declared twice in the main method.
I know that nothing in the above code indicates that I actually have a Loan class. Is this code in a different package, and I'm just missing an import? Please any help would be great. thanks
this is what I have so far
import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.TitledBorder; public class LoanCalculator extends JApplet implements ActionListener { private JTextField jtfInterestRate = new JTextField(10); private JTextField jtfYear = new JTextField(10); private JTextField jtfLoan = new JTextField(10); private JTextField jtfMonthlyPay = new JTextField(10); private JTextField jtfTotalPay = new JTextField(10); private JButton jbtCompute = new JButton("Compute Payment"); public LoanCalculator() { this.jtfMonthlyPay.setEditable(false); this.jtfTotalPay.setEditable(false); this.jtfInterestRate.setHorizontalAlignment(4); this.jtfYear.setHorizontalAlignment(4); this.jtfLoan.setHorizontalAlignment(4); this.jtfMonthlyPay.setHorizontalAlignment(4); this.jtfTotalPay.setHorizontalAlignment(4); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(5, 2)); p1.add(new Label("Interest Rate (e.g., 5.5 for 5.5%)")); p1.add(this.jtfInterestRate); p1.add(new Label("Years ")); p1.add(this.jtfYear); p1.add(new Label("Loan Amount")); p1.add(this.jtfLoan); p1.add(new Label("Monthly Payment")); p1.add(this.jtfMonthlyPay); p1.add(new Label("Total Payment")); p1.add(this.jtfTotalPay); p1.setBorder(new TitledBorder( "Enter interest rate, year and loan amount")); JPanel p2 = new JPanel(); p2.setLayout(new FlowLayout(2)); p2.add(this.jbtCompute); add(p1, "Center"); add(p2, "South"); this.jbtCompute.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == this.jbtCompute) { double interest = Double.valueOf(this.jtfInterestRate.getText()).doubleValue(); int year = Integer.valueOf(this.jtfYear.getText()).intValue(); double loanAmount = Double.valueOf(this.jtfLoan.getText()).doubleValue(); Loan loan = new Loan(interest, year, loanAmount); this.jtfMonthlyPay.setText(String.format("%.2f", new Object[] { Double.valueOf(loan.getMonthlyPayment()) })); this.jtfTotalPay.setText(String.format("%.2f", new Object[] { Double.valueOf(loan.getTotalPayment()) })); } } public static void main(String[] args) { JFrame frame = new JFrame("Loan Calulator"); LoanCalculator applet = new LoanCalculator(); frame.add(applet, "Center"); applet.init(); applet.start(); frame.setSize(350, 250); frame.setLocationRelativeTo(null); frame.setVisible(true); } }
The error I keep getting here is at line 71 (Loan loan = new Loan(interest, year, loanAmount); that java cannot find symbol and it points to where Loan is after new.
I've tried adding in a NoClassDefErrorException import and that didn't work. I tried changing the name of the code and that didn't work either. I've even tried adding a public class loan in the main method but I realized then that a class can't be declared twice in the main method.
I know that nothing in the above code indicates that I actually have a Loan class. Is this code in a different package, and I'm just missing an import? Please any help would be great. thanks