e2 yong main
public class tax {
public static void main(String[] args) {
int[][] bracketsFor2002 = {
{6000, 27950, 67700, 141250, 307050}, // Single filer
{12000 , 46700, 112850, 171950, 307050}, // married filing jointly
{6000, 23350, 56425, 85975, 153525}, // married filing separately
{10000, 37450, 96700, 156600, 307050} // head of household
};
double[] ratesFor2002 = {0.1, 0.15, 0.27, 0.30, 0.35, 0.386};
taxcompu taxcompuFor2002 = new taxcompu(0, bracketsFor2002, ratesFor2002, 50000);
System.out.println("2010 taxcompu Table");
System.out.println("taxcompuable\tSingle\tMarried \tHead of");
System.out.println("Income\tSingle\tJoint\tSeparate\ta House");
for (int taxcompuableIncome = 50000; taxcompuableIncome <= 60000; taxcompuableIncome += 1000) {
taxcompuFor2002.settaxcompuableIncome(taxcompuableIncome);
taxcompuFor2002.setFilingStatus(0);
int taxcompuForStatus0 = (int)taxcompuFor2002.findtaxcompu();
taxcompuFor2002.setFilingStatus(1);
int taxcompuForStatus1 = (int)taxcompuFor2002.findtaxcompu();
taxcompuFor2002.setFilingStatus(2);
int taxcompuForStatus2 = (int)taxcompuFor2002.findtaxcompu();
taxcompuFor2002.setFilingStatus(3);
int taxcompuForStatus3 = (int)taxcompuFor2002.findtaxcompu();
System.out.println(taxcompuableIncome + "\t" + taxcompuForStatus0 + "\t" +
taxcompuForStatus1 + "\t" + taxcompuForStatus2 + "\t" +
taxcompuForStatus3);
}
}
}
e2 nman ung CLASS
class taxcompu {
public final static int SINGLE_FILER = 1;
public final static int MARRIED_JOINTLY = 2;
public final static int MARRIED_SEPARATELY = 3;
public final static int HEAD_OF_HOUSEHOLD = 4;
private int filingStatus = SINGLE_FILER;
private int[][] brackets = {
{27050, 65550, 136750, 297350}, // Single filer
{45200, 109250, 166500, 297350}, // married filing jointly
{22600, 54625, 83250, 148675}, // married filing separately
{36250, 93650, 151650, 297350} // head of household
};
private double[] rates = {0.15, 0.275, 0.305, 0.355, 0.391};
private double taxcompuableIncome = 100000;
public taxcompu() {
}
public taxcompu(int filingStatus, int[][] brackets, double[] rates,
double taxcompuableIncome) {
this.filingStatus = filingStatus;
this.brackets = brackets;
this.rates = rates;
this.taxcompuableIncome = taxcompuableIncome;
}
public void setBrackets(int[][] brackets) {
this.brackets = brackets;
}
public void setRates(double[] rates) {
this.rates = rates;
}
public double gettaxcompuableIncome() {
return taxcompuableIncome;
}
public void settaxcompuableIncome(double taxcompuableIncome) {
this.taxcompuableIncome = taxcompuableIncome;
}
public int getFilingStatus() {
return filingStatus;
}
public void setFilingStatus(int filingStatus) {
this.filingStatus = filingStatus;
}
public double findtaxcompu() {
double taxcompu = 0;
int i;
// Compute taxcompu in the possible 2nd, 3rd, 4th, and 5th brackets
for (i = 1; i < brackets[0].length; i++) {
if (taxcompuableIncome > brackets[filingStatus])
taxcompu += (brackets[filingStatus] - brackets[filingStatus][i - 1]) *
rates;
else {
taxcompu += (taxcompuableIncome - brackets[filingStatus][i - 1]) * rates;
break;
}
}
// Compute taxcompu in the possible last bracket
if (i == brackets[0].length && taxcompuableIncome > brackets[filingStatus][i - 1])
taxcompu += (taxcompuableIncome - brackets[filingStatus][i - 1]) * rates;
return taxcompu;
}
}
revise lang ung program to input and looping
example:
SINGLE_FILER (0 ), MARRIED_JOINTLY (1 ), MARRIED_SEPARATELY (2 ), HEAD_OF_HOUSEHOLD (3 )
if nag input po siya ng 0 ung SINGLE_FILER tax computation lang lalabas
Income Single
50000 10368
51000 10643
52000 10918
53000 11193
54000 11468
55000 11743
56000 12018
57000 12293
58000 12568
59000 12843
60000 13118