Define a class Employee having the following description :
Instance variables :
int pan – to store personal account number
String name – to store name
double taxIncome – to store annual taxable income
double tax – to store tax that is calculated
Member functions :
input ( ) – Store the pan number, name, taxable income
calc( ) – Calculate tax for an employee
display ( ) – Output details of an employee
Write a program to compute the tax according to the given conditions and display the output as per given format.
Total Annual Taxable Income Tax Rate
Upto Rs, 1,00,000 No tax
From 1,00,001 to 1,50,000 10% of the income exceeding Rs. 1,00,000
From 1,50,001 to 2,50,000 Rs. 5000 + 20% of the income exceeding Rs. 1,50,000
Above Rs. 2,50,000 Rs. 25,000 + 30% of the income exceeding Rs. 2,50,000
Output :
Pan Number Name Tax-income Tax
======= ========== ========= =====
======= ========== ========= =====
======= ========== ========= =====
Solution
import java.io.*;
/**
* class Employee
*
*
*/
class Employee
{
// instance variables
int pan;
String name;
double taxIncome, tax;
// read the data from keyboard
public void input()throws IOException
{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
System.out.println("Enter the name, pan and taxable income : ");
name = br.readLine();
pan = Integer.parseInt(br.readLine());
taxIncome = Double.parseDouble(br.readLine());
}
// Method calculate tax
public void calc()
{
tax = 0.0;
if( (taxIncome > 100000) && (taxIncome <= 150000) )
tax = (taxIncome - 100000) * 0.1;
else if( (taxIncome > 150000) && (taxIncome <= 250000) )
tax = 5000.0 + (taxIncome - 150000) * 0.2;
else
tax = 25000.0 + (taxIncome - 250000) * 0.3;
}
// display details of an employee
public void display()
{
System.out.println("Pan Number Name Tax-income Tax");
System.out.println(pan+" " + name + " " + taxIncome + " " + tax);
}
// Main method
public static void main(String args[])throws IOException
{
Employee ob=new Employee();
ob.input();
ob.calc();
ob.display();
}
}
Output:
Enter the name, pan and taxable income :
Abdulla
20938
150000
Pan Number Name Tax-income Tax
20938 Abdulla 150000.0 5000.0
No comments:
Post a Comment