Commit 715d57c
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
@@ -24,12 +24,13 @@ public class TaxReturn {
this.income = income;
this.status = status;
this.children = children;
+ if (this.isSingle()) this.income -= children * 5000;
}
public double getTax() {
double tax = 0;
- if (status == SINGLE) {
+ if (isSingle()) {
if (income <= SINGLE_BRACKET1) tax = RATE1 * income;
else if (income <= SINGLE_BRACKET2)
tax = RATE1 * SINGLE_BRACKET1 + RATE2 * (income - SINGLE_BRACKET1);
@@ -38,8 +39,6 @@ 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)
@@ -60,6 +59,10 @@ public class TaxReturn {
public static final double MARRIED_BRACKET1 = 35800;
public static final double MARRIED_BRACKET2 = 86500;
+ private boolean isSingle() {
+ return this.status == SINGLE;
+ }
+
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Please enter your income: ");
assignments/assignment1/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java
@@ -20,19 +20,18 @@ public class TaxReturnTest extends TestCase {
public void test_SINGLE_BRACKET1_1_CHILD() {
assertEquals(
- 3217.4985 - 5000,
- new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 1).getTax());
+ 2467.4985, new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 1).getTax());
}
public void test_SINGLE_BRACKET1_2_CHILDREN() {
assertEquals(
- 3217.4985 - 10000,
+ 1717.4985000000001,
new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 2).getTax());
}
public void test_SINGLE_BRACKET1_3_CHILDREN() {
assertEquals(
- 3217.4985 - 15000,
+ 967.4985000000001,
new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 3).getTax());
}