Answer:
Scanner inputObject = new Scanner(System.in);
System.out.print("Enter your income to calculate the tax: ");
double income = inputObject.nextDouble();
double tax = 0;
if (income <= 50000) {
tax = income * 0.01;
}
else if (income > 50000 && income <= 75000) {
tax = income * 0.02;
}
else if (income > 75000 && income <= 100000) {
tax = income * 0.03;
}
else if (income > 100000 && income <= 250000) {
tax = income * 0.04;
}
else if (income > 250000 && income <= 500000) {
tax = income * 0.05;
}
else if (income >= 500000) {
tax = income * 0.06;
}
System.out.printf("Your tax is: $%.2f", tax);
Step-by-step explanation:
Here is the Java version of the solution. The user is asked to enter the income and the tax is printed accordingly.
Scanner class is used to take input from user, and the value is stored in income variable. A variable named tax is initialized to store the value of the tax.
Then, if structure is used to check the income value. This income value is checked to decide the amount of the tax will be paid. For example, if the income is $100000, the tax will be calculated as tax = 100000 * 0.03 which is equal to $3000.00. After calculating the tax value, it is printed out using System.out.printf("Your tax is: $%.2f", tax);.
Be aware that the values are double, printf is used to print the value. "%.2f" means print the two decimal values in the result.