vendredi 13 août 2021

Nested If Statement Not Updating Variable [duplicate]

I am trying to create a simple program which calculates and shows the income tax of the user's entered income. I declared a variable called tax which is not updating in the nested If statement. For example if I enter the income as $8000 then it should give me the tax as $710 but it proceeds to give me $230. Any idea on why this is happening and how to resolve this?

import java.util.*;

public class IncomeTax{

public static void main(String [] args){
    
    Scanner scan = new Scanner(System.in);      
    System.out.print("Enter the Amount of Payable Taxable Income: $");      
    double income = scan.nextDouble();      
    double tax = 0.0;
    
    if(income < 750){
        
        tax = income * (1/100);
    }
    else if(income >= 750 & income < 2250){
        
        if(income > 750){
            
            tax = 7.50 + (income * (2/100));
        }
        else{
            
            tax = 7.50;
        }
    }
    else if(income >= 2250 & income < 3750){
        
        if(income > 2250){
            
            tax = 37.50 + (income * (3/100));
        }
        else{
            
            tax = 37.50;
        }
    }
    else if(income >= 3750 & income < 5250){
        
        if(income > 3750){
            
            tax = 82.50 + (income * (4/100));
        }
        else{
            
            tax = 82.50;
        }
    }
    else if(income >= 5250 & income < 7000){
        
        if(income > 5250){
            
            tax = 142.50 + (income * (5/100));
        }
        else{
            
            tax = 142.50;
        }
    }
    else if(income >= 7000){
        
        if(income > 7000){
            
            tax = 230 + (income * (6/100));
        }
        else{
            
            tax = 230.0;
        }
    }
    
    System.out.println();
    System.out.println("The Tax Payable on This Income Is : $"+tax);
}

}

Aucun commentaire:

Enregistrer un commentaire