Tax Refund Calculator......Need help finishing this code!!
Code :
//I need the program to take user input and then calculate the tax refund after the user clicks the "compute refund" button.
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.event.*;
public class TaxRefund extends JFrame
{
private JTextField jtfSalaryIncome = new JTextField();
private JTextField jtfInterestIncome = new JTextField();
private JTextField jtfItemizedDeductions = new JTextField();
private JTextField jtfExemptions = new JTextField();
private JTextField jtfTaxWithheld = new JTextField();
private JButton jbtComputeRefund = new JButton("Compute Refund:");
private JTextField jtfRefund = new JTextField();
public TaxRefund ()
{
JPanel p1 = new JPanel(new GridLayout(5,2,3,3));
p1.add(new JLabel("Salary Income:"));
p1.add(jtfSalaryIncome);
p1.add(new JLabel("Interest Income:"));
p1.add(jtfInterestIncome);
p1.add(new JLabel("Itemized Deductions:"));
p1.add(jtfItemizedDeductions);
p1.add(new JLabel("Exemptions:"));
p1.add(jtfExemptions);
p1.add(new JLabel("Tax Withheld:"));
p1.add(jtfTaxWithheld);
JPanel p2 = new JPanel(new GridLayout(2,2,3,3));
p2.add(new JLabel(""));
p2.add(new JButton("Compute Loan:"));
p2.add(new JLabel("Refund:"));
p2.add(jtfRefund);
add(p1, BorderLayout.CENTER);
add(p2, BorderLayout.SOUTH);
jbtComputeRefund.addActionListener(new ButtonListener());
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int salaryIncome = Integer.parseInt(jtfSalaryIncome.getText());
int interestIncome = Integer.parseInt(jtfInterestIncome.getText());
int itemizedDeductions = Integer.parseInt(jtfItemizedDeductions.getText());
int exemptions = Integer.parseInt(jtfExemptions.getText());
int taxWithheld = Integer.parseInt(jtfTaxWithheld.getText());
Refund getRefund = new getRefund(salaryIncome, interestIncome, itemizedDeductions, exemptions, taxWithheld);
jtfRefund.setText(refund.getRefund());
//I am recieving errors with the preceeding 2 lines of code, Im not sure why.
}
public static void main(String[] args)
{
TaxRefund frame = new TaxRefund();
frame.pack();
frame.setTitle("Project 2: Tax Refund");
frame.setSize(500, 250);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public int getRefund(int salaryIncome, int interestIncome, int itemizedDeductions, int exemptions, int taxWithheld)
{
int refund = 0, taxOwed;
int grossIncome = salaryIncome + interestIncome;
int exemptionAmount = exemptions * 2700;
int taxableIncome = grossIncome - (exemptionAmount + itemizedDeductions);
if (taxableIncome > 0 && taxableIncome < 50001)
taxOwed = (int) (taxableIncome * .05);
else if (taxableIncome < 50000 && taxableIncome < 100001)
taxOwed = (int) (2500 + ((taxableIncome - 50000) * .07));
else if (taxableIncome > 100000)
taxOwed = (int) (6000 + ((taxableIncome - 100000) * .09));
else
taxOwed = 0;
refund = taxWithheld - taxOwed;
return refund;
}
}
Re: Tax Refund Calculator......Need help finishing this code!!
Please explain what your problems are and ask some specific questions about them.
Re: Tax Refund Calculator......Need help finishing this code!!
Refund getRefund = new getRefund(salaryIncome, interestIncome, itemizedDeductions, exemptions, taxWithheld);
jtfRefund.setText(refund.getRefund());
I get an error for these two lines that reads: getRefund cannot be resolved and refund cannot be resolved.
Also I am not getting any results to display inside the Refund label box.
Re: Tax Refund Calculator......Need help finishing this code!!
Quote:
I get an error for these two lines that reads: getRefund cannot be resolved and refund cannot be resolved.
Where are those variables defined? The compiler can not find a definition for them that is in scope where they are being used.