Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Simple java tax program with incorrect output I have a java program that is outp

ID: 3559928 • Letter: S

Question

Simple java tax program with incorrect output

I have a java program that is outputting the wrong numbers. What did I do wrong?

Here are numbers the program should output:

Sample 1:
Enter the filing status: 0
Enter the taxable income: 100000
Tax is 21720.0

Sample 2:
Enter the filing status: 1
Enter the taxable income: 300339
Tax is 76932.87

Sample 3:
Enter the filing status: 2
Enter the taxable income: 123500
Tax is 29665.5

Sample 4:
Enter the filing status: 3
Enter the taxable income: 4545402
Tax is 1565250.7

Here is the code:

public void theProgram() {
        int choice;
        int income;
        Scanner input = new Scanner(System.in);

        System.out.println("Personal Income Tax Calculator ");
        System.out.println("Filing status options: ");
        System.out.println(" 0 - Single");
        System.out
                .println(" 1 - Married Filing Jointly or Qualified Widow(er)");
        System.out.println(" 2 - Married Filing Seperately");
        System.out.println(" 3 - Head of Household");
        System.out.println("To quit enter 4. ");

        System.out.print("Enter your filing status: ");
        choice = input.nextInt();

        if (choice >= 0 && choice <= 3) {
            System.out.print("Enter the taxable income: ");
            income = input.nextInt();

            while (income < 0) {
                System.out.println("Error: Please enter a positive number.");
                System.out.print("Enter the taxable income: ");
                income = input.nextInt();
            }

            while (income >= 0) {
                switch (choice) {
                    case 0:
                        System.out.printf("Tax is $%.2f ", single(income));
                        break;
                    case 1:
                        System.out.printf("Tax is $%.2f ", marriedFilingJointly(income));
                        break;
                    case 2:
                        System.out.printf("Tax is $%.2f ", marriedFillingSeperately(income));
                        break;
                    case 3:
                        System.out.printf("Tax is $%.2f ", headOfHousehold(income));
                        break;
                }

                System.out.println();

                System.out.print("Enter your filing status: ");
                choice = input.nextInt();

                System.out.print("Enter the taxable income: ");
                income = input.nextInt();
            }
        }
    }

    public double single(int income) {
        if (income >= 0 && income <= 8350) {
            return income * 0.1;
        }
        if (income >= 8351 && income <= 33950) {
            return income * 0.15;
        }
        if (income >= 33951 && income <= 82250) {
            return income * 0.25;
        }
        if (income >= 82251 && income <= 171550) {
            return income * 0.28;
        }
        if (income >= 171551 && income <= 372950) {
            return income * 0.33;
        }
        if (income >= 372951) {
            return income * 0.35;
        } else {
            return 0;
        }
    }

    public double marriedFilingJointly(int income) {
        if (income >= 0 && income <= 16700) {
            return income * 0.1;
        }
        if (income >= 16701 && income <= 67900) {
            return income * 0.15;
        }
        if (income >= 67901 && income <= 137050) {
            return income * 0.25;
        }
        if (income >= 137051 && income <= 208850) {
            return income * 0.28;
        }
        if (income >= 208851 && income <= 372950) {
            return income * 0.33;
        }
        if (income >= 372951) {
            return income * 0.35;
        } else {
            return 0;
        }
    }

    public double marriedFillingSeperately(int income) {
        if (income >= 0 && income <= 8350) {
            return income * 0.1;
        }
        if (income >= 8351 && income <= 33950) {
            return income * 0.15;
        }
        if (income >= 33951 && income <= 68525) {
            return income * 0.25;
        }
        if (income >= 68526 && income <= 104425) {
            return income * 0.28;
        }
        if (income >= 104426 && income <= 186475) {
            return income * 0.33;
        }
        if (income >= 186476) {
            return income * 0.35;
        } else {
            return 0;
        }
    }

    public double headOfHousehold(int income) {
        if (income >= 0 && income <= 11950) {
            return income * 0.1;
        }
        if (income >= 11951 && income <= 45500) {
            return income * 0.15;
        }
        if (income >= 45501 && income <= 117450) {
            return income * 0.25;
        }
        if (income >= 117451 && income <= 190200) {
            return income * 0.28;
        }
        if (income >= 190201 && income <= 372950) {
            return income * 0.33;
        }
        if (income >= 372951) {
            return income * 0.35;
        } else {
            return 0;
        }
    }
}

Explanation / Answer

Here is the working code of the above program please post entire list of interest values for the range of amounts as we cannot extract the values from the program i guess the percentage values which you are using might not be the correct values.so please check the percentage values

----------------------------------------------------------------------------------------------------------------------------------------------------------

package javaGUI;

import java.util.Scanner;

public class tax{
   public static void main(String args[])
   {

  
    int choice;
    double income;
    Scanner input = new Scanner(System.in);

    System.out.println("Personal Income Tax Calculator ");
    System.out.println("Filing status options: ");
    System.out.println(" 0 - Single");
    System.out
            .println(" 1 - Married Filing Jointly or Qualified Widow(er)");
    System.out.println(" 2 - Married Filing Seperately");
    System.out.println(" 3 - Head of Household");
    System.out.println("To quit enter 4. ");

    System.out.print("Enter your filing status: ");
    choice = input.nextInt();

    if (choice >= 0 && choice <= 3) {
        System.out.print("Enter the taxable income: ");
        income = input.nextInt();

        while (income < 0) {
            System.out.println("Error: Please enter a positive number.");
            System.out.print("Enter the taxable income: ");
            income = input.nextDouble();
        }

        while (income >= 0) {
            switch (choice) {
                case 0:
                    System.out.printf("Tax is $%.2f ", single(income));
                    break;
                case 1:
                    System.out.printf("Tax is $%.2f ", marriedFilingJointly(income));
                    break;
                case 2:
                    System.out.printf("Tax is $%.2f ", marriedFillingSeperately(income));
                    break;
                case 3:
                    System.out.printf("Tax is $%.2f ", headOfHousehold(income));
                    break;
            }

            System.out.println();

            System.out.print("Enter your filing status: ");
            choice = input.nextInt();

            System.out.print("Enter the taxable income: ");
            income = input.nextInt();
        }
    }
}

static double single(double income) {
    if (income >= 0 && income <= 8350) {
        return (income * 0.1);
    }
    if (income >= 8351 && income <= 33950) {
        return (income * 0.15);
    }
    if (income >= 33951 && income <= 82250) {
        return (income * 0.25);
    }
    if (income >= 82251 && income <= 171550) {
        return (income * 0.28);
    }
    if (income >= 171551 && income <= 372950) {
        return (income * 0.33);
    }
    if (income >= 372951) {
        return (income * 0.35);
    } else {
        return 0;
    }
}

static double marriedFilingJointly(double income) {
    if (income >= 0 && income <= 16700) {
        return (income * 0.1);
    }
    if (income >= 16701 && income <= 67900) {
        return (income * 0.15);
    }
    if (income >= 67901 && income <= 137050) {
        return (income * 0.25);
    }
    if (income >= 137051 && income <= 208850) {
        return (income * 0.28);
    }
    if (income >= 208851 && income <= 372950) {
        return (income * 0.33);
    }
    if (income >= 372951) {
        return (income * 0.35);
    } else {
        return 0;
    }
}

static double marriedFillingSeperately(double income) {
    if (income >= 0 && income <= 8350) {
        return (income * 0.10);
    }
    if (income >= 8351 && income <= 33950) {
        return (income * 0.15);
    }
    if (income >= 33951 && income <= 68525) {
        return (income * 0.25);
    }
    if (income >= 68526 && income <= 104425) {
        return (income * 0.28);
    }
    if (income >= 104426 && income <= 186475) {
        return (income * 0.33);
    }
    if (income >= 186476) {
        return (income * 0.35);
    } else {
        return 0;
    }
}

static double headOfHousehold(double income) {
    if (income >= 0 && income <= 11950) {
        return (income * 0.10);
    }
    if (income >= 11951 && income <= 45500) {
        return (income * 0.15);
    }
    if (income >= 45501 && income <= 117450) {
        return (income * 0.25);
    }
    if (income >= 117451 && income <= 190200) {
        return (income * 0.28);
    }
    if (income >= 190201 && income <= 372950) {
        return (income * 0.33);
    }
    if (income >= 372951) {
        return (income * 0.35);
    } else {
        return 0;
    }
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote