Java program
given below is a hypothetical table showing rates of income tax for male citizens below the age of65yrs:
Does not exceed Rs.1,60,000 -Nil
Is>Rs.1,60,000&<=Rs.50,000 -(ti-1,60,000)*10%
Is>Rs.5,00,000&<=Rs.8,00,000 -[(ti-5,00,000)*20%]+34,000
Is>Rs.8,00,000 -[(ti-8,00,000)*30%]+94,000
Write a program to input the age, gender (male or female) and taxable income (ti) of a person.
If the age is more than 65yrs or the gender is female, display "wrong category".
If the age is less than or equal to 65yrs and the gender is male,compute and display the income tax payable as per the table given above.
write in the util package.
Answers
public class IncomeTax
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter your Age: ");
int age = sc.nextInt();
System.out.print("Enter your gender [M/F] : ");
char gen = sc.next().charAt(0);
if(gen=='f'||gen=='F')
{
System.out.println("Wrong Category");
}
else if(gen=='m'||gen=='M')
{
if(age>65)
{
System.out.println("Wrong Category");
}
else
{
System.out.print("Enter your income: ");
double inc = sc.nextDouble();
double tax;
if(inc<=160000)
{
tax=0;
}
else if((inc>160000)&&(inc<=500000))
{
tax = (inc-160000)*0.1;
}
else if((inc>500000)&&(inc<=800000))
{
tax = (inc-500000)*0.2;
tax += 34000;
}
else
{
tax = (inc-800000)*0.3;
tax += 94000;
}
System.out.println("\nIncome Tax is INR "+tax);
}
}
else
{
System.out.println("Invalid Gender");
}
}
}
Explanation:
import java.util.Scanner;
public class KboatIncomeTax
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = in.nextLine();
System.out.print("Enter age: ");
int age = in.nextInt();
System.out.print("Enter taxable income: ");
double ti = in.nextDouble();
double tax = 0.0;
if (age > 60) {
System.out.print("Wrong Category");
}
else {
if (ti <= 250000)
tax = 0;
else if (ti <= 500000)
tax = (ti - 160000) * 10 / 100;
else if (ti <= 1000000)
tax = 34000 + ((ti - 500000) * 20 / 100);
else
tax = 94000 + ((ti - 1000000) * 30 / 100);
}
System.out.println("Name: " + name);
System.out.println("Tax Payable: " + tax);
}
}