summaryrefslogtreecommitdiff
path: root/src/Q2
diff options
context:
space:
mode:
authormo <mo.khan@gmail.com>2019-05-25 15:27:51 -0600
committermo <mo.khan@gmail.com>2019-05-25 15:27:51 -0600
commit856c35dbc7080922bfff7c10a7a844a9d0a1cd65 (patch)
tree739b413bc2a29adc35229ef2fd9b30581601a206 /src/Q2
parent46f68298527e0c59b9f34003b687259477093fde (diff)
start assignment 2
Diffstat (limited to 'src/Q2')
-rw-r--r--src/Q2/BonusOnSavings.java101
-rw-r--r--src/Q2/BonusOnSavingsTest.java27
-rw-r--r--src/Q2/README.md171
3 files changed, 0 insertions, 299 deletions
diff --git a/src/Q2/BonusOnSavings.java b/src/Q2/BonusOnSavings.java
deleted file mode 100644
index 2872d02..0000000
--- a/src/Q2/BonusOnSavings.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Assignment 1, COMP268 Class: BonusOnSavings.java
- *
- * @description Represents an object that can compute a bonus based on the amount an employee saves.
- * @author: mo khan Student ID: 3431709
- * @date May 7, 2019
- * @version 1.0
- */
-package Q2;
-
-import java.util.Scanner;
-
-public class BonusOnSavings {
- double annualRate = 0.0;
- double quarterlyRate = 0.0;
-
- /** Constructs a BonusOnSavings with a default quarterly rate of 3% and annual rate of 5%. */
- public BonusOnSavings() {
- this(0.03, 0.05);
- }
-
- /**
- * Constructs a BonusOnSavings object for a given income and marital status, and computes the tax.
- *
- * @param quarterlyRate the quarterly rate to apply.
- * @param annualRate the annual rate to apply.
- */
- public BonusOnSavings(double quarterlyRate, double annualRate) {
- this.quarterlyRate = quarterlyRate;
- this.annualRate = annualRate;
- }
-
- /**
- * Computes the bonus based on the target monthly commitment and the actual quarterly
- * contributions.
- *
- * @param monthlyCommitment the target monthly commitment for each month.
- * @param q1 the actual contribution for the first quarter.
- * @param q2 the actual contribution for the second quarter.
- * @param q3 the actual contribution for the third quarter.
- * @param q4 the actual contribution for the fourth quarter.
- * @return the calculated bonus amount for the year.
- */
- public double computeBonus(double monthlyCommitment, double q1, double q2, double q3, double q4) {
- double quarterlyTarget = monthlyCommitment * 3;
- double annualTarget = monthlyCommitment * 12;
-
- return this.quarterlyBonus(quarterlyTarget, q1)
- + this.quarterlyBonus(quarterlyTarget, q2)
- + this.quarterlyBonus(quarterlyTarget, q3)
- + this.quarterlyBonus(quarterlyTarget, q4)
- + this.annualBonus(annualTarget, q1 + q2 + q3 + q4);
- }
-
- /**
- * Computes the quarterly bonus for a given target and actual contribution amount.
- *
- * @param target the target quarterly contribution amount for this employee.
- * @param actual the actual quarterly contribution amount for this employee.
- * @return the calculated quarterly bonus
- */
- private double quarterlyBonus(double target, double actual) {
- return (actual >= target) ? actual * this.quarterlyRate : 0.0;
- }
-
- /**
- * Calculates the annual bonus amount for the target annual contribution and the actual
- * contribution.
- *
- * @param target the target annual contribution
- * @param actual the actual contribution amount for the year
- * @return the calculated annual bonus
- */
- private double annualBonus(double target, double actual) {
- if (actual < target) return 0.0;
-
- return (actual * this.annualRate) + ((actual - target) * 0.25);
- }
-
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print("Please enter your target monthly contribution: ");
- double monthlyCommitment = in.nextDouble();
-
- System.out.print("Please enter Q1 contributions: ");
- double q1 = in.nextDouble();
-
- System.out.print("Please enter Q2 contributions: ");
- double q2 = in.nextDouble();
-
- System.out.print("Please enter Q3 contributions: ");
- double q3 = in.nextDouble();
-
- System.out.print("Please enter Q4 contributions: ");
- double q4 = in.nextDouble();
-
- double bonus = new BonusOnSavings().computeBonus(monthlyCommitment, q1, q2, q3, q4);
-
- System.out.println("The calculated bonus is " + bonus);
- }
-}
diff --git a/src/Q2/BonusOnSavingsTest.java b/src/Q2/BonusOnSavingsTest.java
deleted file mode 100644
index 91198fd..0000000
--- a/src/Q2/BonusOnSavingsTest.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package ca.mokhan.test;
-
-import Q2.*;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class BonusOnSavingsTest extends TestCase {
- private BonusOnSavings subject;
-
- public BonusOnSavingsTest(String testName) {
- super(testName);
- this.subject = new BonusOnSavings();
- }
-
- public static Test suite() {
- return new TestSuite(BonusOnSavingsTest.class);
- }
-
- public void testComputeBonusEmployeeOne() {
- assertEquals(1650.00, subject.computeBonus(2000, 5000, 7000, 4000, 8000));
- }
-
- public void testComputeBonusEmployeeTwo() {
- assertEquals(4680.00, subject.computeBonus(3000, 6000, 9000, 10000, 17000));
- }
-}
diff --git a/src/Q2/README.md b/src/Q2/README.md
deleted file mode 100644
index 1c66db0..0000000
--- a/src/Q2/README.md
+++ /dev/null
@@ -1,171 +0,0 @@
-Learning Profile for Assignment #1, And Question #2
-
-Name: Mo Khan
-Student ID: 3431709
-
-1. Problem Statement:
-
-Space Inc. will give a quarterly and annual bonus to its employees only if the savings of the quarter and/or
-the year are greater than or equal to quarterly minimum (monthly commitment x 3) and/or the annual minimum (monthly commitment x 12) amount, respectively.
-
-The quarterly bonus is 3% of eligible quarterly savings, and the annual bonus is 5% of annual savings if eligible.
-If the annual savings exceeds the committed amount by at least 25%, Space Inc. matches the additional savings (25% or above) as part of the annual bonus.
-
-I. An employee has committed to save $2000 per month.
-
-Her quarterly savings are as follows:
-
-* Q1 – $5000
-* Q2 – $7000
-* Q3 – $4000
-* Q4 – $8000
-
-II. Another employee has committed to save $3000 per month.
-His quarterly savings are as follows:
-
-* Q1 – $6000
-* Q2 – $9000
-* Q3 – $10000
-* Q4 – $17000
-
-Write a program to compute the total bonus amount earned by these two employees in the year.
-
-2. Description of the Code:
-
-I created a class that implemented the interface described in the
-assignment. To calculate the bonus for the year I created a method
-called `quarterlyBonus` to calculate the bonus for each month. I also
-created a method called `annualBonus` to calculate the additional bonus
-for the annual target. Then I summed the quarterly bonuses with the
-annual bonus to calculate the final bonus amount.
-
-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:
-[Provide some test cases with sample input and output of your program.]
-
-The test cases can be found in `BonusOnSavingsTest.java`.
-
-5. Discussion:
-
-I manually calculated the expected bonuses to make sure that I
-understood the problem and how to calculate a result.
-
-Employee 1
-
-Her quarterly savings are as follows:
-
-* Q1 – $5000
-* Q2 – $7000
-* Q3 – $4000
-* Q4 – $8000
-
-Quarterly minimum: $6,000
-Annual minimum: $24,000
-
-* Q1: Does not meet quarterly minimum.
-* Q2: Exceeds quarterly minimum. $7000 * 3% = $210
-* Q3: Does not meet quarterly minimum
-* Q4: Exceeds quarterly minimum. $8000 * 3% = $240.
-* Y1: $24,000.00 meets the annual minimum. $24,000.00 * 5% = $1,200.00
-
-Total bonus: 210 + 240 + 1200 = $1,650.00
-
-Employee 2
-
-* Q1 – $6000
-* Q2 – $9000
-* Q3 – $10000
-* Q4 – $17000
-
-Quarterly min: $9000.00
-Annual min: $36,000.00
-
-* Q1: does not meet quarterly min.
-* Q2: $9,000 * 3% = $270.00
-* Q3: $10,000 * 3% = $300.00
-* Q4: $17,000 * 3% = $510.00
-* Y1: $42,000.00 saved. $42,000.00 * 5% = $2,100.00
-
-42,000 - 36,000 = $6,000 * 25% = $1,500.00
-
-Total: $270.00 + $300.00 + $510.00 + $2,100.00 + $1,500.00
-$4,680.00
-
-Then I started by writing tests to reproduce the expected results. Once
-I had a working test, I began to implment the code to make the test
-pass. After I got the tests passing I started to refactor the code by
-extracting methods.