previous | start | next

File TaxReturn.java

1 /**
2    A tax return of a taxpayer in 1992.
3 */
4 class TaxReturn
5 {  
6    /**
7       Constructs a TaxReturn object for a given income and 
8       marital status.
9       @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_CUTOFF1)
25             tax = RATE1 * income;
26          else if (income <= SINGLE_CUTOFF2)
27             tax = SINGLE_BASE2
28                + RATE2 * (income - SINGLE_CUTOFF1);
29          else
30             tax = SINGLE_BASE3
31                + RATE3 * (income - SINGLE_CUTOFF2);
32       }
33       else
34       {  
35          if (income <= MARRIED_CUTOFF1)
36             tax = RATE1 * income;
37          else if (income <= MARRIED_CUTOFF2)
38             tax = MARRIED_BASE2
39                + RATE2 * (income - MARRIED_CUTOFF1);
40          else
41             tax = MARRIED_BASE3
42                + RATE3 * (income - MARRIED_CUTOFF2);
43       }
44
45       return tax;
46    }
47
48    public static final int SINGLE = 1;
49    public static final int MARRIED = 2;
50
51    private static final double RATE1 = 0.15;
52    private static final double RATE2 = 0.28;
53    private static final double RATE3 = 0.31;
54
55    private static final double SINGLE_CUTOFF1 = 21450;
56    private static final double SINGLE_CUTOFF2 = 51900;
57
58    private static final double SINGLE_BASE2 = 3217.50;
59    private static final double SINGLE_BASE3 = 11743.50;
60    private static final double MARRIED_CUTOFF1 = 35800;
61    private static final double MARRIED_CUTOFF2 = 86500;
62    
63    private static final double MARRIED_BASE2 = 5370;
64    private static final double MARRIED_BASE3 = 19566;
65
66    private double income;
67    private int status;
68 }


previous | start | next