I\'m keep getting 40% tax rate regardless of the amount of gross imcome I type i
ID: 3645125 • Letter: I
Question
I'm keep getting 40% tax rate regardless of the amount of gross imcome I type in.What have I got wrong here?
//Request input from the user
//Calculate Tax Rate
String grossIncomeString = JOptionPane.showInputDialog("Enter your gross income: ");
grossIncome = Double.parseDouble(grossIncomeString);
double taxrate = 0;
double [] taxRates = {0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,0.20,0.21,0.22,0.23,0.24,0.25,0.26,0.27,0.28,0.29,0.30,0.31,0.32,0.33,0.34,0.35,0.36,0.37,0.38,0.39,0.40};
int [] incomeLevels = {5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000, 120000, 125000, 130000, 135000, 140000, 145000, 150000};
for(int i=0; i<incomeLevels.length;i++)
{
if(grossIncome < incomeLevels[i])
{
taxrate = taxRates[i];
}
}
double TaxObligation = TaxableIncome * taxrate;
}
Explanation / Answer
there might be two reason first reason is that you have to change your directory because program is not reading your program but anyother with the same name and same commands. other is that try following program //Request input from the user //Calculate Tax Rate String grossIncomeString = JOptionPane.showInputDialog("Enter your gross income: "); grossIncome = Double.parseDouble(grossIncomeString); double taxrate; double [] taxRates = {0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,0.20,0.21,0.22,0.23,0.24,0.25,0.26,0.27,0.28,0.29,0.30,0.31,0.32,0.33,0.34,0.35,0.36,0.37,0.38,0.39,0.40}; int [] incomeLevels = {5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000, 120000, 125000, 130000, 135000, 140000, 145000, 150000}; for(int i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.