user3314485
user3314485

Reputation: 1

Getting operand errors when running tax program

These are the errors I get when I attempt to run my program below..have no clue how to solve them..just started learning java:

C:\Users\Bryce\Desktop\1504\taxable.java:14: error: bad operand types for binary operator '<'
         (salary >= 15000<20000) {
                         ^
  first type:  boolean
  second type: int

C:\Users\Bryce\Desktop\1504\taxable.java:17: error: bad operand types for binary operator '<='
         (salary>=15000<=35000); {
                       ^
  first type:  boolean
  second type: int
2 errors

Process completed.
------------------------------------------------------------------------------------------

Code:

import java.util.*;
public class taxable {
    public static void main (String[] args) {
         Scanner in=new Scanner(System.in);

         System.out.println("Enter your salary:");
         double salary=in.nextDouble();
         double taxDue;
         if (salary < 15000) {
           System.out.println("No tax applicable");
         }
             if (salary >= 15000<20000) {
           taxDue=15000*10/100;
         }
             if (salary>=15000<=35000);
             {
           taxDue=15000*10/100+20000*20/100;
         }
             if (salary > 35000);
         {
               taxDue=(15000*10/100)+(20000*20/100)+(salary-35000)*35/100;
         }
         System.out.printf("The amount of tax due is: " + taxDue + " ");
         double avTaxRate;
         avTaxRate=taxDue/salary*100;
         System.out.printf("The average tax rate: " + taxDue + "%%");
    }
}

Upvotes: 0

Views: 56

Answers (2)

aalku
aalku

Reputation: 2878

Some errors:

  • The expression salary>=15000<=35000 is wrong in java and I don't know what do you think it means. Same here salary>=15000<=35000. Maybe you want to say salary > x && salary <= y.
  • This is legal but most probably wrong if (salary>=15000<=35000); {. You may want to remove the semicolon or otherwise the code between brackets will always run, it is not part of the if clause.

Upvotes: 0

Warlord
Warlord

Reputation: 2826

salary >= 15000<20000 is not a valid construction, as salary >= 15000 is evaluated into boolean and (boolean) < 20000 is not valid. If you want to do multiple comparisons, you can break it up into multiple clauses, such as

if (salary >= 15000 && salary < 20000) {
}

For more reading about construction of if-clauses, you can visit Java tutorials

Upvotes: 1

Related Questions