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);
Explanation:
Here is the Java version of the solution. The user is asked to enter the income and the tax is printed accordingly.
<em>Scanner</em> class is used to take input from user, and the value is stored in <em>income</em> variable. A variable named <em>tax</em> is initialized to store the value of the tax.
Then, if structure is used to check the <em>income</em> value. This <em>income</em> value is checked to decide the amount of the tax will be paid. For example, if the <em>income</em> is $100000, the tax will be calculated as tax = 100000 * 0.03 which is equal to $3000.00. After calculating the <em>tax</em> value, it is printed out using System.out.printf("Your tax is: $%.2f", tax);.
Be aware that the values are <u>double,</u> <u>printf</u> is used to print the value. "<u>%.2f</u>" means print the<em> </em><u>two decimal values</u> in the result.