01: /**
02:    A tax return of a taxpayer in 1992.
03: */
04: public class TaxReturn
05: {  
06:    /**
07:       Constructs a TaxReturn object for a given income and 
08:       marital status.
09:       @param anIncome the taxpayer income
10:       @param aStatus either SINGLE or MARRIED
11:    */   
12:    public TaxReturn(double anIncome, int aStatus)
13:    {  
14:       income = anIncome;
15:       status = aStatus;
16:    }
17: 
18:    public double getTax()
19:    {  
20:       double tax = 0;
21: 
22:       if (status == SINGLE)
23:       {  
24:          if (income <= SINGLE_BRACKET1)
25:             tax = RATE1 * income;
26:          else if (income <= SINGLE_BRACKET2)
27:             tax = RATE1 * SINGLE_BRACKET1
28:                   + RATE2 * (income - SINGLE_BRACKET1);
29:          else
30:             tax = RATE1 * SINGLE_BRACKET1
31:                   + RATE2 * (SINGLE_BRACKET2 - SINGLE_BRACKET1)
32:                   + RATE3 * (income - SINGLE_BRACKET2);
33:       }
34:       else
35:       {  
36:          if (income <= MARRIED_BRACKET1)
37:             tax = RATE1 * income;
38:          else if (income <= MARRIED_BRACKET2)
39:             tax = RATE1 * MARRIED_BRACKET1
40:                   + RATE2 * (income - MARRIED_BRACKET1);
41:          else
42:             tax = RATE1 * MARRIED_BRACKET1
43:                   + RATE2 * (MARRIED_BRACKET2 - MARRIED_BRACKET1)
44:                   + RATE3 * (income - MARRIED_BRACKET2);
45:       }
46: 
47:       return tax;
48:    }
49: 
50:    public static final int SINGLE = 1;
51:    public static final int MARRIED = 2;
52: 
53:    private static final double RATE1 = 0.15;
54:    private static final double RATE2 = 0.28;
55:    private static final double RATE3 = 0.31;
56: 
57:    private static final double SINGLE_BRACKET1 = 21450;
58:    private static final double SINGLE_BRACKET2 = 51900;
59: 
60:    private static final double MARRIED_BRACKET1 = 35800;
61:    private static final double MARRIED_BRACKET2 = 86500;
62: 
63:    private double income;
64:    private int status;
65: }