public class exerciseFive {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
double finalTax = 0.0;
char taxGroup = 0;
int taxIncome = 0;
int income = 0;
int deduction = 0;
int amount;
do {
System.out.println("Enter next amount: ");
amount = scanner.nextInt();
if (amount > 0) {
income += amount;
}
else if (amount < 0) {
deduction -= amount;
}
} while (amount != 0);
System.out.println("Income = $" + income);
System.out.println("Deductions = $" + deduction);
System.out.println("Taxable Income = $" + taxableIncome(income, deduction, taxIncome));
System.out.println("Tax Group = " + taxGroup(taxIncome, taxGroup));
//System.out.println("Tax Owed = $" + computeTax(taxGroup, taxIncome, finalTax));
}
public static int taxableIncome (int income, int deduction, int taxIncome) {
taxIncome = income - deduction;
if (taxIncome <= 0) {
taxIncome = 0;
}
return taxIncome;
}
public static char taxGroup (int taxIncome, char taxGroup) {
if (taxIncome >= 500_000) {
taxGroup = 'S';
}
else if (taxIncome >= 200_000 && taxIncome < 500000) {
taxGroup = 'Q';
}
else if (taxIncome >= 100_000) {
taxGroup = 'M';
}
else if (taxIncome >= 50_000) {
taxGroup = 'A';
}
else if (taxIncome >= 20_000) {
taxGroup = 'R';
}
else {
taxGroup = 'P';
}
return taxGroup;
}
My output:
Income = $228000
Deductions = $3450
Taxable Income = $224550
Tax Group = P
Correct Output:
Income = $228000.0
Deductions = $3450.0
Taxable income = $224550.0
Tax group = Q
I believe the issue is in this method. I pass the char taxGroup as an argument in the taxGroup method but it is not being updated by the for-loop. I think it may have something to do with the variable being declared in the main method?? Thanks in advance for any help.
As you can see from the output my income, deductions, and taxable income are all correct. The only thing that is wrong is the Tax group.