Hello, I need help making a table based off my tax code I made, the tax code was a little, but I need help with the table part also. The table should look like this:

Income   Single    Married Joint   Married Separate  Head of house
50000    9846        7296              10398                     8506
50050     9859       7309              10411                     8519
........
59950    12532       9982              13190                     11192
60000    12546       9996              13205                    11206

Here is my code:

//Input: put in the income for the single, married, or head of the household taxes
//Process: Using a method to computeing and determining the taxes by less then eual to and by substracting
//Output: Display the results
//Purpose: The program computes the tax for the taxable income based on the filing status


import javax.swing.JOptionPane;


public class ComputeTaxWithMethod {
public static void main (String [] args) {
// Prompt the user to enter filing status
String letters = JOptionPane.showInputDialog(
"Enter the filing status:");
int status = Integer.parseInt(letters);


// Prompt the user to enter taxable income
String symbol = JOptionPane.showInputDialog(
"Enter the taxable income:");
double income = Double.parseDouble(symbol);


//Display the result
JOptionPane.showMessageDialog(null, "Tax is " +
(int)(computeTax(status, income) * 100) / 100.0);


System.out.println("income  \t\t tax ");
System.out.println("________________________");
System.out.println(income + "\t\t" + (int)(computeTax(status, income) * 100) / 100.0);



}



public static double computeTax(double income,
int r1, int r2, int r3, int r4, int r5) {
double tax = 0;


if (income <= r1)
tax = income * 0.10;
else if (income <= r2)
tax = r1 * 0.10 + (income - r1) * 0.15;
else if (income <= r3)
tax = r1 * 0.10 +  (r2 - r1) * 0.15 + (income - r2) * 0.27;
else if (income <= r4)
tax = r1 * 0.10 + (r2 - r1) * 0.15 + (r3 - r2) * 0.27 + (income - r4) * 0.35;
else
tax = r1 * 0.10 + (r2 - r1) * 0.15 + (r3 - r2) * 0.27 + (r4 - r3) * 0.30 + (r5 - r4) * 0.35 + (income - r5) * 0.386;


return tax;
}


public static double computeTax(int status, double income) {
switch (status) {
case 0: return //Compute tax for Single
computeTax(income, 6000, 27950, 67700, 141250, 307050);
case 1: return //Compute tax for married joint
computeTax(income, 12000, 46700, 112850, 171950, 307050);
case 2: return //Compute tax for married separately
computeTax(income, 6000, 23350, 56425, 85975, 153525);
case 3: return //Compute tax for head of a house
computeTax(income, 10000, 37450, 96700, 156600, 307050);
default: return 0;
}
}
}

Edited 3 Years Ago by happygeek: fixed formatting

Justed puted your code between tags so it more readable. Please use them in the future...

import javax.swing.JOptionPane;

public class ComputeTaxWithMethod {
	public static void main (String [] args) {
		// Prompt the user to enter filing status
		String letters = JOptionPane.showInputDialog(
		"Enter the filing status:");
		int status = Integer.parseInt(letters);
		
		// Prompt the user to enter taxable income
		String symbol = JOptionPane.showInputDialog(
		"Enter the taxable income:");
		double income = Double.parseDouble(symbol);
		
		//Display the result
		JOptionPane.showMessageDialog(null, "Tax is " +
		(int)(computeTax(status, income) * 100) / 100.0);
		
		System.out.println("income \t\t tax ");
		System.out.println("________________________");
		System.out.println(income + "\t\t" + (int)(computeTax(status, income) * 100) / 100.0);	
	}
	
	
	public static double computeTax(double income,
	int r1, int r2, int r3, int r4, int r5) {
		
		double tax = 0;
		
		if (income <= r1)
		tax = income * 0.10;
		else if (income <= r2)
		tax = r1 * 0.10 + (income - r1) * 0.15;
		else if (income <= r3)
		tax = r1 * 0.10 + (r2 - r1) * 0.15 + (income - r2) * 0.27;
		else if (income <= r4)
		tax = r1 * 0.10 + (r2 - r1) * 0.15 + (r3 - r2) * 0.27 + (income - r4) * 0.35;
		else
		tax = r1 * 0.10 + (r2 - r1) * 0.15 + (r3 - r2) * 0.27 + (r4 - r3) * 0.30 + (r5 - r4) * 0.35 + (income - r5) * 0.386;
		
		return tax;
	}
	
	public static double computeTax(int status, double income) {
		switch (status) {
			case 0: return //Compute tax for Single
			computeTax(income, 6000, 27950, 67700, 141250, 307050);
			case 1: return //Compute tax for married joint
			computeTax(income, 12000, 46700, 112850, 171950, 307050);
			case 2: return //Compute tax for married separately
			computeTax(income, 6000, 23350, 56425, 85975, 153525);
			case 3: return //Compute tax for head of a house
			computeTax(income, 10000, 37450, 96700, 156600, 307050);
			default: return 0;
		}
	}
}
public class test {

    public static void main(String[] args) {
        // Display the number title

                System.out.println("Taxable      Single    Married/    Married/    Head of");
                System.out.print("Income        Filer     Joint      Separate     House");


                System.out.println("\n----------------------------------------------------------");

                // Display table body
                double taxableIncome = 50000;
                while (taxableIncome <= 60000){
                    System.out.printf("%3.0f" + " | ", taxableIncome);

                    for (int status = 0; status < 4; status++) {
                        // Display the product and align properly
                        System.out.printf("%11.0f", computetax(status, taxableIncome));
                    }
                    System.out.println("");
                    taxableIncome = taxableIncome + 50;
                }
            }


        public static double computetax(int status, double taxableIncome) {

            double tax = 0;

            if (status == 0) {
                if (taxableIncome <= 8350)
                    tax = taxableIncome * 0.10;
                 else if (taxableIncome <= 33950)
                        tax = 8350 * 0.10 + (taxableIncome - 8350) * 0.15;
                      else if (taxableIncome <= 82250)
                        tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                          (taxableIncome - 33950) * 0.25;           
            }
            else if (status == 1) {
                if (taxableIncome <= 16700)
                    tax = taxableIncome * 0.10;
                    else if (taxableIncome <= 67900)
                        tax = 16700 * 0.10 + (taxableIncome - 16700) * 0.15;
            }
            else if (status == 2) {
                if (taxableIncome <= 8350)
                    tax = taxableIncome * 0.10;
                 else if (taxableIncome <= 33950)
                        tax = 8350 * 0.10 + (taxableIncome - 8350) * 0.15;
                      else if (taxableIncome <= 68525)
                        tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
                          (taxableIncome - 33950) * 0.25;
            }
            else if (status == 3) {
                if (taxableIncome <= 11950)
                    tax = taxableIncome * 0.10;
                else if (taxableIncome <= 45500)
                    tax = 11950 * 0.10 + (taxableIncome - 11950) * 0.15;
                else if (taxableIncome <= 117450)
                    tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +
                    (taxableIncome - 45500) * 0.25;
            }
            return tax;
        }


}
This question has already been answered. Start a new discussion instead.