Page 240 - Computer science 868 Class 12
P. 240
if (sumPrimeDigits == sumDigits)
System.out.println(n + " is a Smith Number.");
else
System.out.println(n + " is not a Smith Number.");
}
else
{
System.out.println(n + " is not a Smith Number.");
}
}
}
3. 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 function tax(String name, int income) which displays the name of the employee and the
income tax as per the tariff given below:
Annual Income : Income Tax
Up to ₹2,50,000 : No tax
₹2,50,001 to ₹5,00,000 : 10% 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
Ans. import java.util.*;
class Tax_Calculation
{
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" + "\t" + "Income Tax");
System.out.println( name +"\t" + tax);
}
public static void main()
{
Scanner sc = new Scanner(System.in);
String n;
int ann_inc;
System.out.print("Enter name: ");
n = sc.nextLine();
System.out.print("Enter annual income: ");
ann_inc = sc.nextInt();
Tax_Calculation obj = new Tax_Calculation();
obj.tax(n, ann_inc);
}
}
238238 Touchpad Computer Science-XII

