Computer Applications

Define a class Employee having the following description:

Class name : Employee

Data MembersPurpose
int panTo store personal account number
String nameTo store name
double taxincomeTo store annual taxable income
double taxTo store tax that is calculated
Member functionsPurpose
void input()Store the pan number, name, taxable income
void cal()Calculate tax on taxable income
void display()Output details of an employee

Calculate tax based on the given conditions and display the output as per the given format.

Total Annual Taxable IncomeTax Rate
Up to ₹2,50,000No tax
From ₹2,50,001 to ₹5,00,00010% of the income exceeding ₹2,50,000
From ₹5,00,001 to ₹10,00,000₹30,000 + 20% of the income exceeding ₹5,00,000
Above ₹10,00,000₹50,000 + 30% of the income exceeding ₹10,00,000

Output:

Pan Number  Name    Tax-Income  Tax
..........  ....    ..........  ...
..........  ....    ..........  ...

Java

Java Classes

ICSE 2008

168 Likes

Answer

import java.util.Scanner;

public class Employee
{
    private int pan;
    private String name;
    private double taxincome;
    private double tax;
    
    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter pan number: ");
        pan = in.nextInt();
        in.nextLine();
        System.out.print("Enter Name: ");
        name = in.nextLine();
        System.out.print("Enter taxable income: ");
        taxincome = in.nextDouble();
    }
    
    public void cal() {
        if (taxincome <= 250000)
            tax = 0;
        else if (taxincome <= 500000)
            tax = (taxincome - 250000) * 0.1;
        else if (taxincome <= 1000000)
            tax = 30000 + ((taxincome - 500000) * 0.2);
        else
            tax = 50000 + ((taxincome - 1000000) * 0.3);
    }
    
    public void display() {
        System.out.println("Pan Number\tName\tTax-Income\tTax");
        System.out.println(pan + "\t" + name + "\t" 
            + taxincome + "\t" + tax);
    }
    
    public static void main(String args[]) {
        Employee obj = new Employee();
        obj.input();
        obj.cal();
        obj.display();
    }
}

Variable Description Table

Program Explanation

Output

Answered By

72 Likes


Related Questions