Java Reference
In-Depth Information
We could write the tax calculation code using the && operation and four
if
statements as follows:
if
(taxSal <= 50)
taxAmt = 0;
if
((taxSal > 50) && (taxSal <= 150))
taxAmt = taxSal - 50 * .12;
if
((taxSal > 150) && (taxSal <= 550))
taxAmt = 12 + taxSal - 150 * .15;
if
((taxSal > 550) && (taxSal <= 1150))
taxAmt = 72 + taxSal - 550 * .25;
else
taxAmt = 222 + taxSal - 1150 * .28;
Figure
6-6
shows this logic.
Figure 6-6.