Commit 93762f2

mokha <mokha@cisco.com>
2019-05-06 01:08:42
add additional tax for income from $150,000 - $250,000
1 parent 33ee1f0
Changed files (2)
assignments
assignment1
src
main
java
ca
mokhan
assignment1
test
java
ca
mokhan
assignments/assignment1/src/main/java/ca/mokhan/assignment1/TaxReturn.java
@@ -3,9 +3,6 @@ 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;
@@ -39,6 +36,8 @@ public class TaxReturn {
             RATE1 * SINGLE_BRACKET1
                 + RATE2 * (SINGLE_BRACKET2 - SINGLE_BRACKET1)
                 + RATE3 * (income - SINGLE_BRACKET2);
+
+      if (income > 249999.0) tax += (income - 150000) * 0.25;
     } else {
       if (income <= MARRIED_BRACKET1) tax = RATE1 * income;
       else if (income <= MARRIED_BRACKET2)
@@ -54,8 +53,14 @@ public class TaxReturn {
 
   public static final int SINGLE = 1;
   public static final int MARRIED = 2;
+
+  public static final double RATE1 = 0.15;
+  public static final double RATE2 = 0.28;
+  public 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;
 
assignments/assignment1/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java
@@ -43,6 +43,19 @@ public class TaxReturnTest extends TestCase {
     assertEquals(11743.5031, subject.getTax());
   }
 
+  // if the income is greater than $249,999 for SINGLE, then add a tax of 25% on income amount above
+  // $150,000;
+  public void test_SINGLE_Income_Greater_Than_250K() {
+    // $0 - $21450: 0.15% = $3,217.5
+    // $21450 - $51900: 0.28% = $8,526.0
+    // $51900 - $250,000: 0.31% = $61411.0
+    // $150,000 - $250,000: 0.25% = $25,000.0
+    // total: $98,154.50
+
+    TaxReturn subject = new TaxReturn(250000, TaxReturn.SINGLE);
+    assertEquals(98154.50, subject.getTax());
+  }
+
   public void test_MARRIED_BRACKET1() {
     TaxReturn subject = new TaxReturn(TaxReturn.MARRIED_BRACKET1 - 0.01, TaxReturn.MARRIED);
     assertEquals(5369.9985, subject.getTax());