summaryrefslogtreecommitdiff
path: root/src/Q10/TaxReturn.java
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2019-05-05 19:57:14 -0600
committermokha <mokha@cisco.com>2019-05-05 19:57:14 -0600
commit7b4cb6a2eef3a0fcde7e998832427c73599e4a0a (patch)
tree75acc7cd8f3bd8a087e909db182c9e18a66879a1 /src/Q10/TaxReturn.java
parent99a28d2dba93642e89a62ecf905a3bd4f138318d (diff)
use the exact naming convention for directories described by instructor
Diffstat (limited to 'src/Q10/TaxReturn.java')
-rw-r--r--src/Q10/TaxReturn.java91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/Q10/TaxReturn.java b/src/Q10/TaxReturn.java
new file mode 100644
index 0000000..91a226a
--- /dev/null
+++ b/src/Q10/TaxReturn.java
@@ -0,0 +1,91 @@
+package ca.mokhan.assignment1;
+
+import java.util.Scanner;
+
+public class TaxReturn {
+ 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 income the taxpayer income
+ * @param status either SINGLE or MARRIED
+ */
+ 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;
+ if (this.isSingle()) this.income -= children * 5000;
+ }
+
+ public double getTax() {
+ double tax = 0;
+
+ if (isSingle()) {
+ if (income <= SINGLE_BRACKET1) tax = RATE1 * income;
+ else if (income <= SINGLE_BRACKET2)
+ tax = RATE1 * SINGLE_BRACKET1 + RATE2 * (income - SINGLE_BRACKET1);
+ else
+ tax =
+ 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)
+ tax = RATE1 * MARRIED_BRACKET1 + RATE2 * (income - MARRIED_BRACKET1);
+ else
+ tax =
+ RATE1 * MARRIED_BRACKET1
+ + RATE2 * (MARRIED_BRACKET2 - MARRIED_BRACKET1)
+ + RATE3 * (income - MARRIED_BRACKET2);
+
+ if (income > 349999.0) tax += (income - 200000) * 0.35;
+ }
+ return tax;
+ }
+
+ 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;
+
+ 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: ");
+ double income = in.nextDouble();
+
+ System.out.print("Enter S (single) or M (married): ");
+ String input = in.next();
+ int status = 0;
+
+ if (input.equalsIgnoreCase("S")) status = TaxReturn.SINGLE;
+ else if (input.equalsIgnoreCase("M")) status = TaxReturn.MARRIED;
+ else {
+ System.out.println("Bad input.");
+ return;
+ }
+ TaxReturn aTaxReturn = new TaxReturn(income, status);
+ System.out.println("The tax is " + aTaxReturn.getTax());
+ }
+}