Create a GUI to provide a simple tax calculator which looks like the two example
ID: 3844076 • Letter: C
Question
Create a GUI to provide a simple tax calculator which looks like the
two examples given below. (Two so you can check your calculations.)
Here are the details of the design of the window
The JFrame should be divided into three regions using a grid layout:
The WEST region should contain a radio button group to determine whether the taxpayer is filing as Single, Married, or Single, Head-of-Household
The CENTER region should contain an editable tax field where the user will enter the taxable income, a button to calculate the tax amount, a non-editable field to hold calculated tax amount.
The EAST region should contain four checkboxes for four deduction types (Self, Dependent Child, Three-Legged Dog, and Blind Grandmother)
The entire frame should appear with a WHITE background. This may require that you set the background for the JFrame, JPanel, JTextField, JCheckBox, and JRadioButton components.
The only component you need to register is the button to calculate the tax amount
When the button is clicked, the tax amount is calculated and displayed to 2 decimal places.
Here’s how the tax amount is calculated:
Start with the taxable income amount entered by the user.
For each deduction that is checked, take $2,000 off of the taxable income amount.
Multiply the reduced taxable income amount by one of the following tax rates:
32% for Single
28% for Married
22% for Head-of-Household
Sub listings of all Java classes, Print Screens of the two example tax situations given above, and one of your own choosing.
Explanation / Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.awt.FlowLayout;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.SwingUtilities;
public class SwingJRadioButtonDemo extends JFrame {
public SwingJRadioButtonDemo() {
super("Swing JRadioButton Demo");
JRadioButton option1 = new JRadioButton("Linux");
JRadioButton option2 = new JRadioButton("Windows");
JRadioButton option3 = new JRadioButton("Macintosh");
ButtonGroup group = new ButtonGroup();
group.add(option1);
group.add(option2);
group.add(option3);
setLayout(new FlowLayout());
add(option1);
add(option2);
add(option3);
pack();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingJRadioButtonDemo().setVisible(true);
}
});
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.awt.FlowLayout;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.SwingUtilities;
public class SwingJRadioButtonDemo extends JFrame {
public SwingJRadioButtonDemo() {
super("Swing JRadioButton Demo");
JRadioButton option1 = new JRadioButton("Linux");
JRadioButton option2 = new JRadioButton("Windows");
JRadioButton option3 = new JRadioButton("Macintosh");
ButtonGroup group = new ButtonGroup();
group.add(option1);
group.add(option2);
group.add(option3);
setLayout(new FlowLayout());
add(option1);
add(option2);
add(option3);
pack();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingJRadioButtonDemo().setVisible(true);
}
});
}
}