Computer Applications

Write a program in Java to accept the name of an employee and his/her annual income. Pass the name and the annual income to a method Tax(String name, int income) which displays the name of the employee and the income tax as per the given tariff:

Annual IncomeIncome Tax
Up to ₹2,50,000No tax
₹2,50,001 to ₹5,00,00010% of the income exceeding ₹2,50,000
₹5,00,001 to ₹10,00,000₹30,000 + 20% of the amount exceeding ₹5,00,000
₹10,00,001 and above₹50,000 + 30% of the amount exceeding ₹10,00,000

Java

User Defined Methods

72 Likes

Answer

import java.util.Scanner;

public class KboatEmployeeTax
{
    public void tax(String name, int income) {
        
        double tax;
        if (income <= 250000)
            tax = 0;
        else if (income <= 500000)
            tax = (income - 250000) * 0.1;
        else if (income <= 1000000)
            tax = 30000 + ((income - 500000) * 0.2);
        else
            tax = 50000 + ((income - 1000000) * 0.3);
            
        System.out.println("Name: " + name);
        System.out.println("Income Tax: " + tax);
    }
    
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter name: ");
        String n = in.nextLine();
        System.out.print("Enter annual income: ");
        int i = in.nextInt();
        
        KboatEmployeeTax obj = new KboatEmployeeTax();
        obj.tax(n, i);
    }
}

Variable Description Table

Program Explanation

Output

Answered By

26 Likes


Related Questions