vendredi 23 octobre 2020

Is there anyway to execute codes outside the if-else statement in java?

Is there any way to execute codes outside the if-else statement in java? Make the if-else statement will take the code and amount before the if-statement, and execute it. Like from this:

double tax = 0;

if (status ==0) {
    int taxincome0 = 8350;
    int taxincome1 = 33950;
    double taxrate0 = (taxincome0 * 0.10);
    double taxrate1 = ((taxincome1 - taxincome0) * 0.15);
    
    if (income <= taxincome0){
        tax = income * 0.10;
    }
    
    else if (income <= taxincome1){
        tax = taxrate0 + (income - 8350) *0.15;
    }
}

To this:

double tax = 0;
double taxrate0 = (taxincome0 * 0.10);
    double taxrate1 = ((taxincome1 - taxincome0) * 0.15);

if (status ==0) {
    
    /*
    The integer and double shows 2009 U.S. Federal Personal Tax Rates
    It might have change every year by different amount and different Tax Rates
    Program
    */
    int taxincome0 = 8350;
    int taxincome1 = 33950;
    
    if (income <= taxincome0){
        tax = income * 0.10;
    }
    
    else if (income <= taxincome1){
        tax = taxrate0 + (income - 8350) *0.15;
    }
}

Make the if-else statement will direct capture the double taxrate1 = ((taxincome1 - taxincome0) * 0.15);

Aucun commentaire:

Enregistrer un commentaire