The second programming project involves writing a program to calculate state inc
ID: 3537539 • Letter: T
Question
The second programming project involves writing a program to calculate state income tax for a single taxpayer that uses a GUI. The GUI should use the grid layout manager and should looks similar to the following:
The salary income, interest income, itemized deductions, exemptions and tax withheld are input to the program. When the Compute Refund button is clicked, the refund should be computed and displayed. Assume all inputs are in whole dollars.
The refund should be computed as follows. First compute the total gross income as the sum of the salary and interest income. Then compute the taxable income, which is the gross income less the itemized deductions and exemptions. The exemption amount is computed as the number of exemptions multiplied by $2700. Next compute the tax owed for the year according to the following tax table:
Finally, compute the amount of the refund as the amount withheld minus the tax owed. Note that this amount will be negative if additional taxes are owed. Display this amount in the bottom text field rounded to the whole dollar.
Taxable Income Tax Owed From To $0 $50,000 5% of taxable income $50,000 $100,000 $2,500 + 7% of amount above $50,000 $100,000 -- $6,000 + 9% of amount above $100,000Explanation / Answer
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StateIncome extends JFrame implements ActionListener {
private JTextField salary = new JTextField(20), interest = new JTextField(20),
deductions = new JTextField(20), exemptions = new JTextField(20),
taxWithheld = new JTextField(20), refund = new JTextField(20);
private JButton compute = new JButton("Compute Refund");
public StateIncome(){
super ("Calculate Your State Refund");
setSize(350,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.setLayout(new GridLayout(7,2));
add(new JLabel("Salary Income: "));add(salary);
add(new JLabel("Interest Income: "));add(interest);
add(new JLabel("Itemized Deductions: "));add(deductions);
add(new JLabel("Exemptions: "));add(exemptions);
add(new JLabel("Tax Withheld: "));add(taxWithheld);
add(new JLabel(""));add(compute);
add(new JLabel("Refund: "));add(refund);
refund.setEditable(false);
compute.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent event){
double grossIncome = Double.parseDouble(salary.getText())+Double.parseDouble(interest.getText());
double taxableIncome = grossIncome - Double.parseDouble(deductions.getText())- (Double.parseDouble(exemptions.getText())* 2700);
double taxOwed = 0;
}
public static void main(String[] args) {
StateIncome frame = new StateIncome();
frame.setVisible(true);
}