summaryrefslogtreecommitdiff
path: root/src/Q10
diff options
context:
space:
mode:
Diffstat (limited to 'src/Q10')
-rw-r--r--src/Q10/README.md170
-rw-r--r--src/Q10/TaxReturn.java120
-rw-r--r--src/Q10/TaxReturnTest.java91
3 files changed, 0 insertions, 381 deletions
diff --git a/src/Q10/README.md b/src/Q10/README.md
deleted file mode 100644
index 112696a..0000000
--- a/src/Q10/README.md
+++ /dev/null
@@ -1,170 +0,0 @@
-Learning Profile for Assignment #1, And Question #2
-
-Name: Mo Khan
-Student ID: 3431709
-
-1. Problem Statement:
-
-Modify the following program to the specifications given below:
-
-* I. Add a new status `SingleParent` where the tax is computed as a SINGLE but with a further reduction of $5000 per child.
-* II. Add a new tax condition - if the income is greater than $249,999 for SINGLE, then add a tax of 25% on income amount above $150,000; if the income is greater than $349,999 for MARRIED, then add a tax of 35% on income amount above $200,000.
-* III. Unknown status - if the status doesn't belong to `SINGLE` or `MARRIED` or `SINGLE_PARENT`, then compute a 33% tax on the income.
-
-```java
-import java.util.Scanner;
-
-public class TaxReturn {
- public TaxReturn(double anIncome, int aStatus) {
- income = anIncome;
- status = aStatus;
- }
-
- public double getTax() {
- double tax = 0;
- if (status == SINGLE) {
- 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);
- } 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);
- }
- return tax;
- }
-
- 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;
- private static final double SINGLE_BRACKET1 = 21450;
- private static final double SINGLE_BRACKET2 = 51900;
- private static final double MARRIED_BRACKET1 = 35800;
- private static final double MARRIED_BRACKET2 = 86500;
- private double income;
- private int status;
-
- 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());
- }
-}
-```
-
-2. Description of the Code:
-
-I started by adding tests for the existing code. By adding test coverage
-for the existing code, this makes it possible to add new features
-without breaking old features.
-
-I chose to decrease the taxable income in the constructor if the person
-is single.
-
-
-3. Errors and Warnings:
-
-```bash
-モ mvn test
-[INFO] Scanning for projects...
-[INFO]
-[INFO] -------------------< ca.mokhan.comp268:assignment1 >--------------------
-[INFO] Building assignment1 1.0-SNAPSHOT
-[INFO] --------------------------------[ jar ]---------------------------------
-[INFO]
-[INFO] --- fmt-maven-plugin:2.8:format (default) @ assignment1 ---
-[INFO] Processed 48 files (0 reformatted).
-[INFO]
-[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ assignment1 ---
-[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
-[INFO] skip non existing resourceDirectory /Users/mokha/development/gh/comp-268/src/main/resources
-[INFO]
-[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ assignment1 ---
-[INFO] Changes detected - recompiling the module!
-[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
-[INFO] Compiling 24 source files to /Users/mokha/development/gh/comp-268/target/classes
-[INFO]
-[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ assignment1 ---
-[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
-[INFO] skip non existing resourceDirectory /Users/mokha/development/gh/comp-268/src/test/resources
-[INFO]
-[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ assignment1 ---
-[INFO] Changes detected - recompiling the module!
-[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
-[INFO] Compiling 24 source files to /Users/mokha/development/gh/comp-268/target/test-classes
-[INFO]
-[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ assignment1 ---
-[INFO] Surefire report directory: /Users/mokha/development/gh/comp-268/target/surefire-reports
-
--------------------------------------------------------
- T E S T S
--------------------------------------------------------
-Running ca.mokhan.comp268.AppTest
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec
-Running ca.mokhan.test.CandidateTest
-Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.053 sec
-Running ca.mokhan.test.NumberTest
-Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.021 sec
-Running ca.mokhan.test.EmployeeSavingsTest
-Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
-Running ca.mokhan.test.CartesianCoordinateSystemTest
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
-Running ca.mokhan.test.CommunicationTest
-Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
-Running ca.mokhan.test.TaxReturnTest
-Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
-Running ca.mokhan.test.BanffMarathonRunnerTest
-Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
-Running ca.mokhan.test.AddressBookTest
-Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
-Running ca.mokhan.test.TriangleTest
-Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
-Running ca.mokhan.test.BonusOnSavingsTest
-Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
-Running ca.mokhan.test.HailstoneSequenceTest
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
-
-Results :
-
-Tests run: 52, Failures: 0, Errors: 0, Skipped: 0
-
-[INFO] ------------------------------------------------------------------------
-[INFO] BUILD SUCCESS
-[INFO] ------------------------------------------------------------------------
-[INFO] Total time: 2.871 s
-[INFO] Finished at: 2019-05-13T20:07:42-06:00
-[INFO] ------------------------------------------------------------------------
-```
-
-4. Sample Input and Output:
-
-Test cases are defined in `TaxReturnTest.java`.
-
-5. Discussion:
-
-There is a lot of conditional logic in `getTax()`. I considered
-[Refactor conditional with polymorphism](https://refactoring.com/catalog/replaceConditionalWithPolymorphism.html)
-but decided not to make this change.
diff --git a/src/Q10/TaxReturn.java b/src/Q10/TaxReturn.java
deleted file mode 100644
index 7fbd48b..0000000
--- a/src/Q10/TaxReturn.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * Assignment 1, COMP268 Class: TaxReturn.java
- *
- * @description Represents a contact from an address book.
- * @author: mo khan Student ID: 3431709
- * @date May 6, 2019
- * @version 1.0
- */
-package Q10;
-
-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);
- }
-
- /**
- * Constructs a TaxReturn object for a given income and marital status and, and # of children.
- *
- * @param income the taxpayer income
- * @param status either SINGLE or MARRIED
- * @param children the number of children
- */
- public TaxReturn(double income, int status, int children) {
- this.income = income;
- this.status = status;
- this.children = children;
- if (this.isSingle()) this.income -= children * 5000;
- }
-
- /**
- * Returns the calculated taxes to pay.
- *
- * @return the amount of tax to pay.
- */
- 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 (isMarried()) {
- 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;
- } else {
- tax = income * 0.33;
- }
- 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;
- }
-
- private boolean isMarried() {
- return this.status == MARRIED;
- }
-
- 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;
- }
- System.out.print("Enter # of children: ");
- int children = in.nextInt();
-
- TaxReturn aTaxReturn = new TaxReturn(income, status, children);
- System.out.println("The tax is " + aTaxReturn.getTax());
- }
-}
diff --git a/src/Q10/TaxReturnTest.java b/src/Q10/TaxReturnTest.java
deleted file mode 100644
index c1af186..0000000
--- a/src/Q10/TaxReturnTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package ca.mokhan.test;
-
-import Q10.*;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class TaxReturnTest extends TestCase {
- public TaxReturnTest(String testName) {
- super(testName);
- }
-
- public static Test suite() {
- return new TestSuite(TaxReturnTest.class);
- }
-
- public void test_SINGLE_BRACKET1() {
- TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE);
- assertEquals(3217.4985, subject.getTax());
- }
-
- public void test_SINGLE_BRACKET1_1_CHILD() {
- TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 1);
- assertEquals(2467.4985, subject.getTax());
- }
-
- public void test_SINGLE_BRACKET1_2_CHILDREN() {
- TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 2);
- assertEquals(1717.4985000000001, subject.getTax());
- }
-
- public void test_SINGLE_BRACKET1_3_CHILDREN() {
- TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 3);
- assertEquals(967.4985000000001, subject.getTax());
- }
-
- public void test_SINGLE_BRACKET2() {
- TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET2 - 0.01, TaxReturn.SINGLE);
- assertEquals(11743.4972, subject.getTax());
- }
-
- public void test_SINGLE_BRACKET3() {
- TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET2 + 0.01, TaxReturn.SINGLE);
- 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());
- }
-
- public void test_MARRIED_BRACKET2() {
- TaxReturn subject = new TaxReturn(TaxReturn.MARRIED_BRACKET2 - 0.01, TaxReturn.MARRIED);
- assertEquals(19565.997200000005, subject.getTax());
- }
-
- public void test_MARRIED_BRACKET3() {
- TaxReturn subject = new TaxReturn(TaxReturn.MARRIED_BRACKET2 + 0.01, TaxReturn.MARRIED);
- assertEquals(19566.003099999998, subject.getTax());
- }
-
- // if the income is greater than $349,999 for MARRIED, then add a tax of 35% on income amount
- // above $200,000.
- public void test_MARRIED_Income_Greater_Than_350K() {
- // $0 - $35,800: 0.15% = $5,370.0
- // $35,800 - $86,500: 0.28% = $14196.000000000002
- // $86,500 - $350,000: 0.31% = $81685.0
- // $200,000 - $350,000: 0.35% = $52500.0
- // total: $153,751.0
- TaxReturn subject = new TaxReturn(350000, TaxReturn.MARRIED);
- assertEquals(153751.0, subject.getTax());
- }
-
- public void test_UNKNOWN_status_Should_tax_at_33_percent() {
- TaxReturn subject = new TaxReturn(100000, 3);
- assertEquals(33000.0, subject.getTax());
- }
-}