Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Tax Refund Calculator......Need help finishing this code!!

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Tax Refund Calculator......Need help finishing this 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;	
    }
    }
    Last edited by pbrockway2; November 25th, 2012 at 02:03 AM. Reason: code tags added


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,100
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Tax Refund Calculator......Need help finishing this code!!

    Please explain what your problems are and ask some specific questions about them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,100
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Tax Refund Calculator......Need help finishing this code!!

    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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. I need help with my Netbeans calculator code
    By geto81 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 5th, 2012, 12:53 PM
  2. Replies: 11
    Last Post: February 10th, 2012, 04:38 PM
  3. Need help finishing code. List Building...
    By Margaret_Girl87 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 30th, 2011, 05:09 PM
  4. having bad time with basic calculator code
    By hashey100 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2011, 08:29 PM
  5. Help needed with calculator code
    By andys in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 21st, 2011, 08:02 PM