Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on this code currently and I want it to print an array of 10 lines showing the taxable income, filing status and the total tax due from that individual one per line. I'm not quite sure how to do it. I've tried numerous times but I keep getting stuck. If anyone could help me I would appreciate it so much.
package finalProg;

import java.util.Scanner;

public class tax {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        String maritalStatus;
        System.out.printf("What is your marital status? \nEnter 'S' for single: \nEnter'M' for married or widowed filling jointly: \nEnter'MS'"
        		+ "for married but filling seperatly: \nEnter'H' for head of household: \n");

        maritalStatus = in.next(); 

        System.out.println("What is your annual income?");
        double income;
        income = in.nextDouble();

         
        double singleTax = 0;
        double marriedTax = 0;
        double marriedSeperatlyTax = 0;
        double headOfHouseholdTax = 0;

        
        //SINGLE
        if (maritalStatus.equals("S")) {
            if (income > 0 && income <= 9700) {
                singleTax = income * .10;
            } else if (income > 9700 && income <= 39475) {
                singleTax = (.12 * (income-9700) + 970);
            } else if (income > 39475 && income <= 84200) {
            	singleTax = (.22 * (income-39475) + 4543);
            } else if (income > 84200 && income <= 160725) {
            	singleTax = (.24 * (income-84200) + 14382);
            } else if (income > 160725 && income <= 204100) {
            	singleTax = (.32 * (income-160725) + 32748);
            } else if (income > 204100 && income <= 510300) {
            	singleTax = (.35 * (income-204100) + 46628);
            } else if (income > 510300) {
            	singleTax = (.37 * (income-510300) + 153798);
            }
            System.out.println("Your income taxes are" + singleTax);  
            
            }
        if (maritalStatus.equals("M")) {
        	//MARRIED JOINT
            if (income > 0 && income <= 19400) {
                marriedTax = income * .10;
            } else if (income > 19400 && income <= 78950) {
            	marriedTax = (.12 * (income-19400) + 1940);
            } else if (income > 78950 && income <= 168400) {
            	marriedTax = (.22 * (income-78950) + 9086);
            } else if (income > 168400 && income <= 321450) {
            	marriedTax = (.24 * (income-168400) + 28765);
            } else if (income > 321450 && income <= 408200) {
            	marriedTax = (.32 * (income-3214500) + 65497);
            } else if (income > 408200 && income <= 612350) {
            	marriedTax = (.35 * (income-408200) + 93257);
            } else if (income > 612350) {
            	marriedTax = (.37 * (income-612350) + 164709);
            }
            System.out.println("Your income taxes are " + marriedTax);
        };
        if (maritalStatus.equals("MS")) {
        	//MARRIED SEPERETLY
            if (income > 0 && income <= 9700) {
            	marriedSeperatlyTax = income * .10;
            } else if (income > 9700 && income <= 39475) {
            	marriedSeperatlyTax = (.12 * (income-9700) + 970);
            } else if (income > 39475 && income <= 84200) {
            	marriedSeperatlyTax = (.22 * (income-39475) + 4543);
            } else if (income > 84200 && income <= 160725) {
            	marriedSeperatlyTax = (.24 * (income-84200) + 14382.50);
            } else if (income > 160725 && income <= 204100) {
            	marriedSeperatlyTax = (.32 * (income-160725) + 32748.50);
            } else if (income > 204100 && income <= 306175) {
            	marriedSeperatlyTax = (.35 * (income-204100) + 46628.50);
            } else if (income > 306175){
            	marriedSeperatlyTax = (.37 * (income-306175) + 82354.75);
            }
            System.out.println("Your income taxes are " + marriedSeperatlyTax);
        };
        if (maritalStatus.equals("H")) {
        	//HEAD OF HOUSEHOLD
            if (income > 0 && income <= 13850) {
            	headOfHouseholdTax = income * .10;
            } else if (income > 13850 && income <= 52850) {
            	headOfHouseholdTax = (.12 * (income-13850) + 1385);
            } else if (income > 52850 && income <= 84200) {
            	headOfHouseholdTax = (.22 * (income-52850) + 6065);
            } else if (income > 84200 && income <= 160700) {
            	headOfHouseholdTax = (.24 * (income-84200) + 12962);
            } else if (income > 160700 && income <= 204100) {
            	headOfHouseholdTax = (.32 * (income-160700) + 31322);
            } else if (income > 204100 && income <= 510300) {
            	headOfHouseholdTax = (.35 * (income-204100) + 45210);
            } else if (income > 510300){
            	headOfHouseholdTax = (.37 * (income-510300) + 152380);
            }
            System.out.println("Your income taxes are " + headOfHouseholdTax);
            }
       
        
      
        in.close();
}

}


What I have tried:

I've been trying to declare an array but no luck. If someone could show me how to print the marital status, the income, and income tax for 10 inputs I would LOVE YOU!
Posted
Updated 9-Apr-20 19:52pm

1 solution

Quote:
I've been trying to declare an array but no luck. If someone could show me how to print the marital status, the income, and income tax for 10 inputs I would LOVE YOU!


I'm sure you would - but ... we are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

And you have shown no attempt to "declare an array" and so no attempt at all to "print the marital status, the income, and income tax for 10 inputs". This is your homework, and it is set to make sure you understand the material you have just been shown - and you clearly don't! Us handing you a solution wouldn't help you learn that - it would mean you didn't have to - and the next piece of homework will assume that you do know it and move on to using it in more complex ways.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900