Commit a7d441b
Changed files (2)
assignments
assignment1
src
main
java
ca
mokhan
assignment1
test
java
ca
mokhan
assignment1
assignments/assignment1/src/main/java/ca/mokhan/assignment1/TaxReturn.java
@@ -3,15 +3,27 @@ package ca.mokhan.assignment1;
import java.util.Scanner;
public class TaxReturn {
+ private static final double RATE1 = 0.15;
+ private static final double RATE2 = 0.28;
+ private static final double RATE3 = 0.31;
+ private double income;
+ private int status;
+ private int children;
+
/**
* Constructs a TaxReturn object for a given income and marital status, and computes the tax.
*
- * @param anIncome the taxpayer income
- * @param aStatus either SINGLE or MARRIED
+ * @param income the taxpayer income
+ * @param status either SINGLE or MARRIED
*/
- public TaxReturn(double anIncome, int aStatus) {
- income = anIncome;
- status = aStatus;
+ public TaxReturn(double income, int status) {
+ this(income, status, 0);
+ }
+
+ public TaxReturn(double income, int status, int children) {
+ this.income = income;
+ this.status = status;
+ this.children = children;
}
public double getTax() {
@@ -26,6 +38,8 @@ public class TaxReturn {
RATE1 * SINGLE_BRACKET1
+ RATE2 * (SINGLE_BRACKET2 - SINGLE_BRACKET1)
+ RATE3 * (income - SINGLE_BRACKET2);
+
+ tax -= this.children * 5000;
} else {
if (income <= MARRIED_BRACKET1) tax = RATE1 * income;
else if (income <= MARRIED_BRACKET2)
@@ -41,15 +55,10 @@ public class TaxReturn {
public static final int SINGLE = 1;
public static final int MARRIED = 2;
- private static final double RATE1 = 0.15;
- private static final double RATE2 = 0.28;
- private static final double RATE3 = 0.31;
public static final double SINGLE_BRACKET1 = 21450;
public static final double SINGLE_BRACKET2 = 51900;
public static final double MARRIED_BRACKET1 = 35800;
public static final double MARRIED_BRACKET2 = 86500;
- private double income;
- private int status;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
assignments/assignment1/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java
@@ -18,6 +18,24 @@ public class TaxReturnTest extends TestCase {
3217.4985, new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE).getTax());
}
+ public void test_SINGLE_BRACKET1_1_CHILD() {
+ assertEquals(
+ 3217.4985 - 5000,
+ new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 1).getTax());
+ }
+
+ public void test_SINGLE_BRACKET1_2_CHILDREN() {
+ assertEquals(
+ 3217.4985 - 10000,
+ new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 2).getTax());
+ }
+
+ public void test_SINGLE_BRACKET1_3_CHILDREN() {
+ assertEquals(
+ 3217.4985 - 15000,
+ new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 3).getTax());
+ }
+
public void test_SINGLE_BRACKET2() {
assertEquals(
11743.4972, new TaxReturn(TaxReturn.SINGLE_BRACKET2 - 0.01, TaxReturn.SINGLE).getTax());