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

How to write a java program for Tax Management System? Write a Java program that

ID: 2246526 • Letter: H

Question

How to write a java program for Tax Management System?

Write a Java program that will calculate tax for the employees of a company called XYZ. The main memu of the tax calculation program is as fo lows. Welcome to Tax Management System of XYZ Please select one of the following options 1. Calculate tax 2. Search tax 3. Exit When 1 is selected then the program will calculate the tax of an employee based on the annual income of the employee and tax rates on the income. The tax rates on the income is stored in a file called taxrates.txt. The program needs to read the taxrates.txt file and store the information in proper data structure. If the taxrates.txt file does not exist in the directory of the source code then the program should ask to provide the taxrates.txt file as an input. The format of the taxrates.txt file is as follows Taxable Income Ta on Income 0 $18,200 $18,201 - $37,000 19c for each $1 over $18,200 $37,001-S87,000$3,572 plus 32.5c for each $1 over $37,000 $87,001-S180,000 $19,822 plus 37c for each $1 over S87,000

Explanation / Answer

TaxApplication.java

import java.util.Scanner;


public class TaxApplication {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        TaxApplication ta = new TaxApplication();
        ta.initiateProgram();
    }

    private void initiateProgram() {
        System.out.println("Welcome to Tax Management system of XYZ");
        System.out.println(" Please select one of the following options:");
        System.out.println(" 1. Calculate Tax");
        System.out.println(" 2. Search Tax");
        System.out.println(" 3. Exit");
        System.out.println(" Enter your option: ");

        Scanner sc = new Scanner(System.in);

        int menuOption = 0;
        try {
            menuOption = sc.nextInt();
        } catch (Exception ex) {

        }

        switch (menuOption) {
            case 1:
                String ans;
                do {
                    System.out.println("Please enter employee id: ");
                    String employeeId = sc.next();

                    float annualIncome = 0;
                    do {
                        System.out.println("Please enter employee annual income: ");
                        while (!sc.hasNextFloat()) {
                            System.out.println("Please enter employee annual income: ");
                            sc.next(); // this is important!
                        }
                        annualIncome = sc.nextFloat();
                    } while (annualIncome <= 0);

                    TaxCalculator tc = new TaxCalculator();
                    tc.calculateTax(employeeId, annualIncome);

                    System.out.println("Do you want to calculate tax for another employee? (Y/N)");
                    ans = sc.next();
                } while (ans.equalsIgnoreCase("y"));

                initiateProgram();

                break;
            case 2:
                TaxSearch ts = new TaxSearch();
                ts.searchTax("123");
                break;
            case 3:
                System.exit(0);
                break;
            default:
                System.out.println("Please enter correct option");
        }
    }
}

TaxCalculator.java

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;


public class TaxCalculator {
  
    private HashMap slabs;

    public TaxCalculator() {
        init();
    }
  
    private void init(){
        if(slabs == null){
            readTaxInfo();
        }
    }
  
    private void readTaxInfo(){
        //write code to read from file taxrates.txt
      
        //hardcode temporarily
        slabs = new HashMap();
        Slab slab1 = new Slab();
        slab1.setMin(0);
        slab1.setMax(18200);
        slab1.setDollarVal(0);
        slab1.setCentVal(0);
      
        slabs.put("slab1", slab1);
      
        Slab slab2 = new Slab();
        slab2.setMin(18200);
        slab2.setMax(37000);
        slab2.setDollarVal(0);
        slab2.setCentVal(19);
      
        slabs.put("slab2", slab2);
      
        Slab slab3 = new Slab();
        slab3.setMin(37000);
        slab3.setMax(87000);
        slab3.setDollarVal(3572);
        slab3.setCentVal(32.5f);
      
        slabs.put("slab3", slab3);
      
        Slab slab4 = new Slab();
        slab4.setMin(87000);
        slab4.setMax(180000);
        slab4.setDollarVal(19822);
        slab4.setCentVal(37);
      
        slabs.put("slab4", slab4);
      
        Slab slab5 = new Slab();
        slab5.setMin(180000);
        slab5.setMax(-1);
        slab5.setDollarVal(54232);
        slab5.setCentVal(45);
      
        slabs.put("slab5", slab5);
    }
  
    public void calculateTax(String employeeId, float annualIncome){
        float tax = 0;
        float taxableIncome = 0;
      
        if(annualIncome <= ((Slab) slabs.get("slab1")).getMax()){
          
            taxableIncome = (annualIncome - ((Slab) slabs.get("slab1")).getMin());
            tax = ((Slab) slabs.get("slab1")).getDollarVal() + (taxableIncome * (((Slab) slabs.get("slab1")).getCentVal() / 100));
      
        }else if(annualIncome > ((Slab) slabs.get("slab2")).getMin() && annualIncome <= ((Slab) slabs.get("slab2")).getMax()){
          
            taxableIncome = (annualIncome - ((Slab) slabs.get("slab2")).getMin());
            tax = ((Slab) slabs.get("slab2")).getDollarVal() + (taxableIncome * (((Slab) slabs.get("slab2")).getCentVal() / 100));
      
        }else if(annualIncome > ((Slab) slabs.get("slab3")).getMin() && annualIncome <= ((Slab) slabs.get("slab3")).getMax()){
          
            taxableIncome = (annualIncome - ((Slab) slabs.get("slab3")).getMin());
            tax = ((Slab) slabs.get("slab3")).getDollarVal() + (taxableIncome * (((Slab) slabs.get("slab3")).getCentVal() / 100));
      
        }else if(annualIncome > ((Slab) slabs.get("slab4")).getMin() && annualIncome <= ((Slab) slabs.get("slab4")).getMax()){
          
            taxableIncome = (annualIncome - ((Slab) slabs.get("slab4")).getMin());
            tax = ((Slab) slabs.get("slab4")).getDollarVal() + (taxableIncome * (((Slab) slabs.get("slab4")).getCentVal() / 100));
      
        }else if(annualIncome > ((Slab) slabs.get("slab5")).getMin()){
          
            taxableIncome = (annualIncome - ((Slab) slabs.get("slab5")).getMin());
            tax = ((Slab) slabs.get("slab5")).getDollarVal() + (taxableIncome * (((Slab) slabs.get("slab5")).getCentVal() / 100));
      
        }
      
        System.out.println("Tax: " + tax);
        System.out.println("Taxable income: " + taxableIncome);
      
//        File taxReport = new File("files:src/files/taxreport.txt");

        try {
            FileWriter writer = new FileWriter("src/files/taxreport.txt", true);
            writer.write(" " + employeeId + " | ");
            writer.write(taxableIncome + " | ");   // write new line
            writer.write(tax + "");
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Slab.java

public class Slab {
    private int min;
    private int max;
    private float dollarVal;
    private float centVal;

    public int getMin() {
        return min;
    }

    public void setMin(int min) {
        this.min = min;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public float getDollarVal() {
        return dollarVal;
    }

    public void setDollarVal(float dollarVal) {
        this.dollarVal = dollarVal;
    }

    public float getCentVal() {
        return centVal;
    }

    public void setCentVal(float centVal) {
        this.centVal = centVal;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote