Design a program in Java to calculate the tax for the people living in Mango city

Question  4.
Design a program in Java to calculate the tax for the people living in Mango city. Specify a class taxpayer whose class description is given below:                                                                                                                                                                                    [15]
Class name:                                         TaxCalculator
Data members:                                    int PAN
                                                                String name
                                                                double  taxableIncome
                                                                double  tax
Member methods:                               inputData()
                                                            displayData()
                                                            computeData()
The tax is calculated according to the following rules:
Total Annual Taxable Income
Rate of Taxation
Up to 60000
0%
Above 60000 but up to 150000
5%
Above 150000 but up to 500000
10%
Above 500000
15%

Solution
import java.io.*;
/**
 * class TaxCalculator here.
 *
*
 */
public class TaxCalculator
{
       int pan;
       String name;
       double taxableIncome;
       double tax;
       void input()throws IOException
       {
              InputStreamReader in=new InputStreamReader(System.in);
              BufferedReader br=new BufferedReader(in);
              System.out.println("Enter name and taxable income:");
              name=br.readLine();
               taxableIncome=Double.parseDouble(br.readLine());
       }
      void computeData()
      {
               if(taxableIncome<=60000)
                   tax=0;
               else if(taxableIncome>60000 && taxableIncome<=150000)
                  tax=taxableIncome*0.05;
               else if(taxableIncome>150000 && taxableIncome<=500000)
                  tax=taxableIncome*0.1;
             else
                  tax=taxableIncome*0.2;
      }
      void displayData()
      {
        System.out.println("Display Data”);
        System.out.println("Name =" + name);
        System.out.println("Taxable Income =" + taxableIncome);
        System.out.println("Tax Paid =" + tax);
    }
    
    public static void main(String args[])throws IOException
    {
        TaxCalculator ob=new TaxCalculator();
        ob.input();
        ob.computeData();
        ob.displayData();
    }
}
Output:
Enter name and taxable income:
Rehan
120000
Display Data
Name=Rehan
Taxable Income=120000.0


Tax Paid=6000.0

No comments:

Post a Comment