Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Want a tax program where there are different calculation for different persons w

ID: 3626754 • Letter: W

Question

Want a tax program where there are different calculation for different persons
want a tax prgram in JAVA language
Different function is to be defined for different calculations
case 1:Where a person is man and whose income is Rs.2,10,000
The next Rs.50,000 is taxable @10%
The remaining Rs.60,000 is taxable @20%
Therefore the net income is Rs.17,000
case 2:Where a person is woman and whose income is Rs.2,40,000
The next Rs.1,35,000 is taxable @10%
The remaining Rs.90,000 is taxable @20%
Therefore the net income is Rs.19,500
case 3:Where a person is senior citizen and whose income is Rs.2,90,000
The next Rs.65,000 is taxable @10%
The remaining Rs.90,000 is taxable @20%
Therefore the net income is Rs.19,500

Explanation / Answer

these r tow sample program for tax calculations in Java import javax.swing.JOptionPane; public class IncomeTax { public static void main (String [] args) { String inputString1; double totalInc; double incomeTax; double incomeTax2; double tax; // get the user's income inputString1 = JOptionPane.showInputDialog("Please enter your income: "); //covert the input to double totalInc = Double.parseDouble(inputString1); //applying the conditions if ((totalInc >= 15001) && (totalInc >= 30000)) { incomeTax = totalInc *.05; tax = incomeTax *.05; } else { incomeTax2 = totalInc *.1; tax = incomeTax2 *.1; } // Display the message box(result) JOptionPane.showMessageDialog(null, "Total income: $ " + totalInc + " Income taxed at 5%: $ "+ incomeTax + " Income taxed at 10%: $ " + incomeTax2 + " Tax: $" +tax ); System.exit(0); } } ----------------------------------- // IncomeTaxCalc.java - SIMPLE INCOME TAX CALCULATOR PROGRAM // // MODULE INDEX // NAME CONTENTS // init Initialise the income tax calculator applet // createGUI() Create graphical user interface // createIncomePanel Create income panel // createOthIncomePanel Create other income panel // createJoinIncomePanel Create join income panel // createTotIncomePanel Create total income panel // createReliefPanel Create relief panel // createChildB18Panel Create child below 18 panel // createChildA18Panel Create child above 18 panel // createOthDdtPanel Create other deduction panel // createTotRelPanel Create total relief panel // createTaxPayablePanel Create tay payable panel // setConstrains Set gridbags layou constrains // showError Show the error message // taxValidation Validate tax input // taxCurrencyFormat Format the currency value // actionPerformed Action performed // calcTax Tax calculation // // MAINTENANCE HISTORY // DATE PROGRAMMER AND DETAILS // 05-03-06 JYS Original // //----------------------------------------------------------------------------- // IMPORTS import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.text.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; //----------------------------------------------------------------------------- // INCOME TAX CALCULATER CLASS DEFINITION public class IncomeTaxCalc extends JApplet implements ActionListener { //------------------------------------------------------------------------- // PARAMETERS private static final double FIRST_TAX_RATE = 0.10; private static final double SECOND_TAX_RATE = 0.18; private static final double REMAINING_TAX_RATE = 0.24; private static final double JOIN_TAX_ON_FIRST = 18500; private static final double JOIN_TAX_ON_SECOND = 58500; private static final double SEPARATE_TAX_ON_FIRST = 10000; private static final double SEPARATE_TAX_ON_SECOND = 34700; //------------------------------------------------------------------------- // INSTANCE DATA private TaxDocListener taxTaxDocListener = new TaxDocListener(); // Tax field document listener private static HashMap taxTaxFieldMap = new HashMap(); // Tax fields map private JRadioButton taxJoinRBut; // Joint assessment radio button private JRadioButton taxSepRBut; // Separate assessment radio button private JLabel taxJoinIncLabel; // Join income label private JLabel taxSpouseIncLabel; // Spouse income label private JRadioButton taxInterRBut; // International business radio button private JRadioButton taxLocRBut; // Local business radio button private TaxTextField taxIncBusTxt; // Income from business field private TaxTextField taxChrBusTxt; // Chargeable business income amount field private TaxTextField taxPatnerTxt; // Patnership chargeable amount field private TaxTextField taxBusNPatTxt; // Business and patnership chargeable amount field private TaxTextField taxFwdTxt; // Business losses bought foward field private TaxTextField taxAggBusNPatTxt; // Aggregate income from business and partnership field private TaxTextField taxEmployTxt; // Employment income field private TaxTextField taxOthIncTxt; // Other income field private TaxTextField taxAggOthTxt; // Aggregate income from other sources field private TaxTextField taxSpouseTranTxt; // Transfered from spouse field private TaxTextField taxTotalIncTxt; // Total Income field private TaxTextField taxDepRefTxt; // Dependent relative field private TaxTextField taxEpfTxt; // EPF field private JCheckBox taxLifChk; // Life insurance checkbox private JCheckBox taxMedChk; // Medical insurance checkbox private TaxTextField taxInsTxt; // Insurance field private JComboBox tax100NoCldCmb; // Number of child for 100% rate combo box private JComboBox tax50NoCldCmb; // Number of child for 50% rate field private TaxTextField tax100CldAmtTxt; // Total 100% child tax relief private TaxTextField tax50CldAmtTxt; // Total 50% child tax relief private TaxTextField taxCldB18AmtTxt; // Total amount child below 18 tax relief private TaxTextField taxFirCldA18Txt; // Age for first child that age above 18 field private TaxTextField taxSecCldA18Txt; // Age for second child that age above 18 field private TaxTextField taxThiCldA18Txt; // Age for third child that age above 18 field private JRadioButton taxFirCldLocRBut; // First child education in malaysia radio button private JRadioButton taxFirCldForRBut; // First child education outside malaysia radio button private JRadioButton taxSecCldLocRBut; // Second child education in malaysia radio button private JRadioButton taxSecCldForRBut; // Second child education outside malaysia radio button private JRadioButton taxThiCldLocRBut; // Third child education in malaysia radio button private JRadioButton taxThiCldForRBut; // Third child education outside malaysia radio button private TaxTextField taxCldA18AmtTxt; // Total amount child above 18 tax relief private TaxTextField taxOthDdtTxt; // Other deduction field private TaxTextField taxTotReliefTxt; // Total relief field private TaxTextField taxChaTaxTxt; // Total chargeable tax private TaxTextField taxFirChaTaxTxt; // First chargeable tax private TaxTextField taxSecChaTaxTxt; // Second chargeable tax private TaxTextField taxRemChaTaxTxt; // Remaining chargeable tax private TaxTextField taxFirTaxTxt; // Tax on first private TaxTextField taxSecTaxTxt; // Tax on second private TaxTextField taxRemTaxTxt; // Tax on remaining private TaxTextField taxTotTaxTxt; // Total income tax private JPanel taxMainPanel; // Tax content panel private GridBagConstraints taxCons; // Grid Bag Constraints private DecimalFormat taxDecFormatter; // Decimal formatter //------------------------------------------------------------------------- // INCOME TAX CALCULATOR'S TEXT FILED CLASS DEFINITION class TaxTextField extends JTextField { //------------------------------------------------------------------------- // CONSTRUCTOR - SPECIFIED NUMBER OF COLUMNS public TaxTextField(int columns) { this (columns, true); } //------------------------------------------------------------------------- // CONSTRUCTOR - SPECIFIED NUMBER OF COLUMNS AND ENABLE FLAG public TaxTextField(int columns, boolean isEnabled) { this (null, "", columns, isEnabled); } //------------------------------------------------------------------------- // CONSTRUCTOR - SPECIFIED TEXT AND ENABLE FLAG public TaxTextField(String text, boolean isEnabled) { this (null, text, 0, isEnabled); } //------------------------------------------------------------------------- // CONSTRUCTOR - SPECIFIED TEXT, COLUMNS AND ENABLE FLAG public TaxTextField(String text, int columns, boolean isEnabled) { this (null, text, columns, isEnabled); } //------------------------------------------------------------------------- // CONSTRUCTOR - SPECIFIED DOCUMENT, TEXT AND COLUMNS public TaxTextField(Document doc, String text, int columns) { this (doc, text, columns, true); } //------------------------------------------------------------------------- // CONSTRUCTOR - SPECIFIED DOCUMENT, TEXT, COLUMNS AND ENABLE FLAG public TaxTextField(Document doc, String text, int colums, boolean isEnabled) { super(doc, text, colums); setHorizontalAlignment(TaxTextField.RIGHT); setEnabled(isEnabled); if (!isEnabled) setText("0"); else { taxTaxFieldMap.put(getDocument(), this); getDocument().addDocumentListener(taxTaxDocListener); } } } //------------------------------------------------------------------------- // INITIATION public void init() { taxDecFormatter = new DecimalFormat("0.00"); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); } }); } catch (Exception e) { System.err.println("createGUI didn't successfully complete"); } } //------------------------------------------------------------------------- // DRAW INCOME TAX CALCULATOR GUI public void createGUI() { Container contentPane; // Applet container JPanel assPanel; // Assessment panel JScrollPane scrollPane; // Scroll panel contentPane = getContentPane(); taxMainPanel = new JPanel(); taxMainPanel.setLayout(new GridBagLayout()); taxCons = new GridBagConstraints(); taxCons.fill = GridBagConstraints.HORIZONTAL; taxCons.insets = new Insets(1,1,1,1); assPanel = createAssessmentPanel(); setConstrains (taxCons, 0, 0, 4, 1, 1, 1); taxMainPanel.add(assPanel, taxCons); createIncomePanel(); createOthIncomePanel(); createJoinIncomePanel(); createTotIncomePanel(); createReliefPanel(); createChildB18Panel(); createChildA18Panel(); createOthDdtPanel(); createTotRelPanel(); createTaxPayablePanel(); scrollPane = new JScrollPane(taxMainPanel); contentPane.add(scrollPane); } //------------------------------------------------------------------------- // DRAW ASSESSMENT PANEL private JPanel createAssessmentPanel() { JPanel assPanel; // assessment panel; JPanel taxMainPanel; // Temporary panel; ButtonGroup btnGrp; // Button Group assPanel = new JPanel(); taxMainPanel = new JPanel(); taxJoinRBut = new JRadioButton ("Joint"); taxJoinRBut.setSelected(true); taxJoinRBut.addActionListener(this); taxSepRBut = new JRadioButton ("Separate"); taxSepRBut.addActionListener(this); btnGrp = new ButtonGroup(); btnGrp.add(taxJoinRBut); btnGrp.add(taxSepRBut); taxMainPanel.add(taxJoinRBut); taxMainPanel.add(taxSepRBut); assPanel.setLayout(new FlowLayout()); assPanel.add(new JLabel("Type of assessment")); assPanel.add(taxMainPanel); return assPanel; } //------------------------------------------------------------------------- // DRAW INCOME PANEL private void createIncomePanel() { ButtonGroup btnGrp; // Button Group taxInterRBut = new JRadioButton("International"); taxInterRBut.addActionListener(this); taxLocRBut = new JRadioButton("Local"); taxLocRBut.addActionListener(this); btnGrp = new ButtonGroup(); btnGrp.add(taxInterRBut); btnGrp.add(taxLocRBut); taxIncBusTxt = new TaxTextField(10); Action[] act = taxIncBusTxt.getActions(); for (int i=0;i -1 && text.length() - text.indexOf(".") > 3) showError (textField, "Invalid input, only 2 decimal places is allowed"); } catch (NumberFormatException ex) { showError(textField, "Invalid input, only numeric input is accepted"); } } //------------------------------------------------------------------------- // CURRENCY FORMAT private String taxCurrencyFormat(String cur) { if (cur.indexOf(".") > -1) if (cur.length() - cur.indexOf(".") < 2) cur += "0"; else cur = cur.substring(0, cur.indexOf(".") + 2); else cur += ".00"; return cur; } //------------------------------------------------------------------------- // ACTION PERFORMED public void actionPerformed( ActionEvent event) { taxJoinIncLabel.setVisible(taxJoinRBut.isSelected()); taxSpouseIncLabel.setVisible(taxJoinRBut.isSelected()); taxSpouseTranTxt.setVisible(taxJoinRBut.isSelected()); tax100NoCldCmb.setEnabled(taxJoinRBut.isSelected()); if (!tax100NoCldCmb.isEnabled()) tax100NoCldCmb.setSelectedIndex(0); calcTax(); } //------------------------------------------------------------------------- // Tax Calculation public void calcTax() { double busInc; // Business income double patInc; // Patnership income double chrBusInc; // Chargeable business income double busNPatInc; // Total of business and patnership income double fwdLos; // Business losses bought foward double aggBusNPat; // Aggregate income from business and patnership double empInc; // Employment income double othInc; // Other income double aggOthInc; // Aggregate income from other source double spouseInc; // Spouse income double totInc; // Total income double depRel; // Dependent relative relief double epfRel; // EPF relief double insRel; // insurance relief double cld100Rel; // Total 100% child tax relief double cld50Rel; // Total 50% cild tax relief double b18CldRel; // Below 18 child relief double a18CldRel; // Above 18 child relief double othDdtRel; // Other deduction relief double totRel; // Total relief double chaTax; // Total chargeable tax double firChaTax; // First chargeable tax double secChaTax; // Second chargeable tax double remChaTax; // Remaining chargeable tax double firTax; // Tax on first chargeable tax double secTax; // Tax on second chargeable tax double remTax; // Tax on remaining chargeable tax double totTax; // Total tax if (taxIncBusTxt.getText().equals("")) busInc = 0; else busInc = Double.parseDouble(taxIncBusTxt.getText()); if (taxInterRBut.isSelected()) chrBusInc = busInc * 1.05; else chrBusInc = busInc * 1.02; if (taxPatnerTxt.getText().equals("")) patInc = 0; else patInc = Double.parseDouble(taxPatnerTxt.getText()); busNPatInc = patInc + chrBusInc; if (taxFwdTxt.getText().equals("")) fwdLos = 0; else fwdLos = Double.parseDouble(taxFwdTxt.getText()); aggBusNPat = busNPatInc - fwdLos; if (taxEmployTxt.getText().equals("")) empInc = 0; else empInc = Double.parseDouble(taxEmployTxt.getText()); if (taxOthIncTxt.getText().equals("")) othInc = 0; else othInc = Double.parseDouble(taxOthIncTxt.getText()); aggOthInc = empInc + othInc; if (taxSpouseTranTxt.getText().equals("")) spouseInc = 0; else spouseInc = Double.parseDouble(taxSpouseTranTxt.getText()); totInc = aggBusNPat + aggOthInc + spouseInc; if (taxJoinRBut.isSelected()) depRel = 0; else depRel = 8000; if (taxEpfTxt.getText().equals("")) epfRel = 0; else epfRel = Double.parseDouble(taxEpfTxt.getText()); insRel = 0; if (taxLifChk.isSelected()) insRel += 3000; if (taxMedChk.isSelected()) insRel += 2000; if (insRel > 4000) insRel = 4000; cld100Rel = Integer.parseInt((String)tax100NoCldCmb.getSelectedItem()) * 1000; cld50Rel = Integer.parseInt((String)tax50NoCldCmb.getSelectedItem()) * 500; b18CldRel = cld100Rel + cld50Rel; a18CldRel = 0; if (!taxFirCldA18Txt.getText().equals("")) { if (taxFirCldLocRBut.isSelected()) a18CldRel += 4000; else a18CldRel += 3000; } if (!taxSecCldA18Txt.getText().equals("")) { if (taxSecCldLocRBut.isSelected()) a18CldRel += 3000; else a18CldRel += 2000; } if (!taxThiCldA18Txt.getText().equals("")) { if (taxThiCldLocRBut.isSelected()) a18CldRel += 1000; else a18CldRel += 500; } if (taxOthDdtTxt.getText().equals("")) othDdtRel = 0; else othDdtRel = Double.parseDouble(taxOthDdtTxt.getText()); if (othDdtRel > 10000) othDdtRel = 10000; totRel = depRel + epfRel + insRel + b18CldRel + a18CldRel + othDdtRel; chaTax = totInc - totRel; if (taxJoinRBut.isSelected()) { if (chaTax > JOIN_TAX_ON_FIRST) firChaTax = JOIN_TAX_ON_FIRST; else firChaTax = chaTax; if (chaTax > JOIN_TAX_ON_SECOND) secChaTax = JOIN_TAX_ON_SECOND - JOIN_TAX_ON_FIRST; else { secChaTax = chaTax - JOIN_TAX_ON_FIRST; if (secChaTax < 0) secChaTax = 0; } remChaTax = chaTax - JOIN_TAX_ON_SECOND; if (remChaTax < 0) remChaTax = 0; } else { if (chaTax > SEPARATE_TAX_ON_FIRST) firChaTax = SEPARATE_TAX_ON_FIRST; else firChaTax = chaTax; if (chaTax > SEPARATE_TAX_ON_SECOND) secChaTax = SEPARATE_TAX_ON_SECOND - SEPARATE_TAX_ON_FIRST; else { secChaTax = chaTax - SEPARATE_TAX_ON_FIRST; if (secChaTax < 0) secChaTax = 0; } remChaTax = chaTax - SEPARATE_TAX_ON_SECOND; if (remChaTax < 0) remChaTax = 0; } firTax = firChaTax * FIRST_TAX_RATE; secTax = secChaTax * SECOND_TAX_RATE; remTax = remChaTax * REMAINING_TAX_RATE; totTax = firTax + secTax + remTax; taxChrBusTxt.setText(taxDecFormatter.format(chrBusInc)); taxBusNPatTxt.setText(taxDecFormatter.format(busNPatInc)); taxAggBusNPatTxt.setText(taxDecFormatter.format(aggBusNPat)); taxAggOthTxt.setText(taxDecFormatter.format(aggOthInc)); taxTotalIncTxt.setText(taxDecFormatter.format(totInc)); taxDepRefTxt.setText(taxDecFormatter.format(depRel)); taxInsTxt.setText(taxDecFormatter.format(insRel)); tax100CldAmtTxt.setText(taxDecFormatter.format(cld100Rel)); tax50CldAmtTxt.setText(taxDecFormatter.format(cld50Rel)); taxCldB18AmtTxt.setText(taxDecFormatter.format(b18CldRel)); taxCldA18AmtTxt.setText(taxDecFormatter.format(a18CldRel)); taxTotReliefTxt.setText(taxDecFormatter.format(totRel)); taxChaTaxTxt.setText(taxDecFormatter.format(chaTax)); taxFirChaTaxTxt.setText(taxDecFormatter.format(firChaTax)); taxSecChaTaxTxt.setText(taxDecFormatter.format(secChaTax)); taxRemChaTaxTxt.setText(taxDecFormatter.format(remChaTax)); taxFirTaxTxt.setText(taxDecFormatter.format(firTax)); taxSecTaxTxt.setText(taxDecFormatter.format(secTax)); taxRemTaxTxt.setText(taxDecFormatter.format(remTax)); taxTotTaxTxt.setText(taxDecFormatter.format(totTax)); } }