summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/ca/mokhan/assignment1/AddressBook.java178
-rw-r--r--src/main/java/ca/mokhan/assignment1/App.java7
-rw-r--r--src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java51
-rw-r--r--src/main/java/ca/mokhan/assignment1/BonusOnSavings.java36
-rw-r--r--src/main/java/ca/mokhan/assignment1/Candidate.java75
-rw-r--r--src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java7
-rw-r--r--src/main/java/ca/mokhan/assignment1/Communication.java40
-rw-r--r--src/main/java/ca/mokhan/assignment1/EmployeeSavings.java84
-rw-r--r--src/main/java/ca/mokhan/assignment1/HailstoneSequence.java17
-rw-r--r--src/main/java/ca/mokhan/assignment1/Number.java46
-rw-r--r--src/main/java/ca/mokhan/assignment1/TaxReturn.java91
-rw-r--r--src/main/java/ca/mokhan/assignment1/Triangle.java29
-rw-r--r--src/test/java/ca/mokhan/assignment1/AddressBookTest.java92
-rw-r--r--src/test/java/ca/mokhan/assignment1/AppTest.java19
-rw-r--r--src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java61
-rw-r--r--src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java26
-rw-r--r--src/test/java/ca/mokhan/assignment1/CandidateTest.java62
-rw-r--r--src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java22
-rw-r--r--src/test/java/ca/mokhan/assignment1/CommunicationTest.java43
-rw-r--r--src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java83
-rw-r--r--src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java39
-rw-r--r--src/test/java/ca/mokhan/assignment1/NumberTest.java58
-rw-r--r--src/test/java/ca/mokhan/assignment1/TaxReturnTest.java85
-rw-r--r--src/test/java/ca/mokhan/assignment1/TriangleTest.java25
24 files changed, 1276 insertions, 0 deletions
diff --git a/src/main/java/ca/mokhan/assignment1/AddressBook.java b/src/main/java/ca/mokhan/assignment1/AddressBook.java
new file mode 100644
index 0000000..9fcfa82
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/AddressBook.java
@@ -0,0 +1,178 @@
+package ca.mokhan.assignment1;
+
+import java.util.Objects;
+
+public class AddressBook implements Comparable<AddressBook> {
+ private String businessPhone;
+ private String cellPhone;
+ private String facebookId;
+ private String firstName = "";
+ private String homeAddress;
+ private String homePhone;
+ private String lastName = "";
+ private String middleName = "";
+ private String personalWebSite;
+ private String skypeId;
+
+ public AddressBook() {
+ this("");
+ }
+
+ public AddressBook(String firstName) {
+ this(firstName, "", "");
+ }
+
+ public AddressBook(String firstName, String middleName, String lastName) {
+ this(firstName, middleName, lastName, "", "", "", "", "", "", "");
+ }
+
+ public AddressBook(
+ String firstName,
+ String middleName,
+ String lastName,
+ String businessPhone,
+ String cellPhone,
+ String facebookId,
+ String homeAddress,
+ String homePhone,
+ String personalWebSite,
+ String skypeId) {
+ this.businessPhone = businessPhone;
+ this.cellPhone = cellPhone;
+ this.facebookId = facebookId;
+ this.firstName = firstName;
+ this.homeAddress = homeAddress;
+ this.homePhone = homePhone;
+ this.lastName = lastName;
+ this.middleName = middleName;
+ this.personalWebSite = personalWebSite;
+ this.skypeId = skypeId;
+ }
+
+ public String getBusinessPhone() {
+ return this.businessPhone;
+ }
+
+ public String getCellPhone() {
+ return this.cellPhone;
+ }
+
+ public String getFacebookId() {
+ return this.facebookId;
+ }
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public String getHomeAddress() {
+ return this.homeAddress;
+ }
+
+ public String getHomePhone() {
+ return this.homePhone;
+ }
+
+ public String getLastName() {
+ return this.lastName;
+ }
+
+ public String getMiddleName() {
+ return this.middleName;
+ }
+
+ public String getPersonalWebSite() {
+ return this.personalWebSite;
+ }
+
+ public String getSkypeId() {
+ return this.skypeId;
+ }
+
+ public void setBusinessPhone(String value) {
+ this.businessPhone = value;
+ }
+
+ public void setCellPhone(String value) {
+ this.cellPhone = value;
+ }
+
+ public void setFacebookId(String value) {
+ this.facebookId = value;
+ }
+
+ public void setFirstName(String name) {
+ this.firstName = name;
+ }
+
+ public void setHomeAddress(String address) {
+ this.homeAddress = address;
+ }
+
+ public void setHomePhone(String value) {
+ this.homePhone = value;
+ }
+
+ public void setLastName(String name) {
+ this.lastName = name;
+ }
+
+ public void setMiddleName(String name) {
+ this.middleName = name;
+ }
+
+ public void setPersonalWebSite(String value) {
+ this.personalWebSite = value;
+ }
+
+ public void setSkypeId(String value) {
+ this.skypeId = value;
+ }
+
+ public static String compareNames(String name1, String name2) {
+ return Integer.toString(name1.compareTo(name2));
+ }
+
+ public int compareTo(AddressBook other) {
+ return this.firstName.compareTo(other.firstName)
+ + this.middleName.compareTo(other.middleName)
+ + this.lastName.compareTo(other.lastName);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof AddressBook)) return false;
+ AddressBook that = (AddressBook) o;
+ return Objects.equals(businessPhone, that.businessPhone)
+ && Objects.equals(cellPhone, that.cellPhone)
+ && Objects.equals(facebookId, that.facebookId)
+ && Objects.equals(firstName, that.firstName)
+ && Objects.equals(homeAddress, that.homeAddress)
+ && Objects.equals(homePhone, that.homePhone)
+ && Objects.equals(lastName, that.lastName)
+ && Objects.equals(middleName, that.middleName)
+ && Objects.equals(personalWebSite, that.personalWebSite)
+ && Objects.equals(skypeId, that.skypeId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ businessPhone,
+ cellPhone,
+ facebookId,
+ firstName,
+ homeAddress,
+ homePhone,
+ lastName,
+ middleName,
+ personalWebSite,
+ skypeId);
+ }
+
+ @Override
+ public String toString() {
+ return this.firstName;
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/App.java b/src/main/java/ca/mokhan/assignment1/App.java
new file mode 100644
index 0000000..6dc05d2
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/App.java
@@ -0,0 +1,7 @@
+package ca.mokhan.assignment1;
+
+public class App {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java b/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java
new file mode 100644
index 0000000..afc0472
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java
@@ -0,0 +1,51 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class BanffMarathonRunner extends AddressBook {
+ private int time;
+ private int years;
+
+ public BanffMarathonRunner(String firstName, String lastName, int time, int years) {
+ super(firstName, "", lastName);
+ this.time = time;
+ this.years = years;
+ }
+
+ public int compareTo(AddressBook other) {
+ BanffMarathonRunner runner = (BanffMarathonRunner) other;
+ return Integer.compare(this.time, runner.time);
+ }
+
+ @Override
+ public String toString() {
+ return super.getFirstName() + " " + this.years;
+ }
+
+ public static BanffMarathonRunner getFastestRunner(BanffMarathonRunner[] runners) {
+ Arrays.sort(runners);
+ return runners[0];
+ }
+
+ public static BanffMarathonRunner getSecondFastestRunner(BanffMarathonRunner[] runners) {
+ Arrays.sort(runners);
+ return runners[1];
+ }
+
+ public static int getAverageTime(BanffMarathonRunner[] runners) {
+ int sum = 0;
+ for (BanffMarathonRunner runner : runners) sum += runner.time;
+ return sum / runners.length;
+ }
+
+ public static String getAboveAverageRunners(BanffMarathonRunner[] runners) {
+ int average = getAverageTime(runners);
+ ArrayList<String> winners = new ArrayList<String>();
+
+ for (BanffMarathonRunner runner : runners)
+ if (runner.time >= average) winners.add(runner.toString());
+
+ return String.join(System.lineSeparator(), winners);
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/BonusOnSavings.java b/src/main/java/ca/mokhan/assignment1/BonusOnSavings.java
new file mode 100644
index 0000000..41090ec
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/BonusOnSavings.java
@@ -0,0 +1,36 @@
+package ca.mokhan.assignment1;
+
+public class BonusOnSavings {
+ double annualRate = 0.0;
+ double quarterlyRate = 0.0;
+
+ public BonusOnSavings() {
+ this(0.03, 0.05);
+ }
+
+ public BonusOnSavings(double quarterlyRate, double annualRate) {
+ this.quarterlyRate = quarterlyRate;
+ this.annualRate = annualRate;
+ }
+
+ 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);
+ }
+
+ private double quarterlyBonus(double target, double actual) {
+ return (actual >= target) ? actual * this.quarterlyRate : 0.0;
+ }
+
+ private double annualBonus(double target, double actual) {
+ if (actual < target) return 0.0;
+
+ return (actual * this.annualRate) + ((actual - target) * 0.25);
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/Candidate.java b/src/main/java/ca/mokhan/assignment1/Candidate.java
new file mode 100644
index 0000000..7df9535
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/Candidate.java
@@ -0,0 +1,75 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+
+public class Candidate extends AddressBook {
+ private double grade = 0.0;
+ private Communication communication;
+ private boolean isInnovative;
+ private double regulatoryCapability;
+
+ public Candidate(
+ String firstName,
+ String lastName,
+ double grade,
+ String communication,
+ boolean isInnovative,
+ double regulatoryCapability) {
+ super(firstName, "", lastName);
+ this.grade = grade;
+ this.setCommunication(communication);
+ this.isInnovative = isInnovative;
+ this.regulatoryCapability = regulatoryCapability;
+ }
+
+ public boolean isInnovative() {
+ return this.isInnovative;
+ }
+
+ public double getGrade() {
+ return this.grade;
+ }
+
+ public double getRegulation() {
+ return this.regulatoryCapability;
+ }
+
+ public String getCommunication() {
+ return this.communication.toString();
+ }
+
+ public void setCommunication(String communication) {
+ this.communication = Communication.findBy(communication);
+ }
+
+ public void setGrade(double grade) {
+ this.grade = grade;
+ }
+
+ public void setInnovation(boolean innovation) {
+ this.isInnovative = innovation;
+ }
+
+ public void setRegulation(double regulatoryCapability) {
+ this.regulatoryCapability = regulatoryCapability;
+ }
+
+ public boolean isEligible() {
+ if (this.grade >= 85.0) {
+ return this.communication.isAtLeast(Communication.Average) || this.isInnovative();
+ } else {
+ return (this.regulatoryCapability >= 0.5
+ && this.communication.isAtLeast(Communication.Average));
+ }
+ }
+
+ public static ArrayList<Candidate> getEligibleCandidates(Candidate[] candidates) {
+ ArrayList<Candidate> eligible = new ArrayList<Candidate>();
+
+ for (Candidate candidate : candidates) {
+ if (candidate.isEligible()) eligible.add(candidate);
+ }
+
+ return eligible;
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java b/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java
new file mode 100644
index 0000000..d6681f9
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java
@@ -0,0 +1,7 @@
+package ca.mokhan.assignment1;
+
+public class CartesianCoordinateSystem {
+ public double calculateDistance(double x1, double y1, double x2, double y2) {
+ return Math.round(Math.pow(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2), 0.5) * 100) / 100.0;
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/Communication.java b/src/main/java/ca/mokhan/assignment1/Communication.java
new file mode 100644
index 0000000..2e4c2a8
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/Communication.java
@@ -0,0 +1,40 @@
+package ca.mokhan.assignment1;
+
+public class Communication implements Comparable<Communication> {
+ private String name;
+ private Integer ranking;
+
+ public Communication(String name, Integer ranking) {
+ this.name = name;
+ this.ranking = ranking;
+ }
+
+ public int compareTo(Communication other) {
+ return this.ranking.compareTo(other.ranking);
+ }
+
+ public boolean isAtLeast(Communication other) {
+ return this.compareTo(other) >= 0;
+ }
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
+
+ public static final Communication Poor = new Communication("poor", 0);
+ public static final Communication Average = new Communication("average", 1);
+ public static final Communication Excellent = new Communication("excellent", 2);
+
+ public static Communication findBy(String name) {
+ switch (name) {
+ case "poor":
+ return Communication.Poor;
+ case "average":
+ return Communication.Average;
+ case "excellent":
+ return Communication.Excellent;
+ }
+ throw new IllegalArgumentException("Unknown communication type");
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java b/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java
new file mode 100644
index 0000000..44eac10
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java
@@ -0,0 +1,84 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import java.util.Currency;
+import java.util.Locale;
+import java.util.Random;
+
+public class EmployeeSavings extends AddressBook {
+ private double accountValue;
+ private double[] monthlyInterests;
+ private double[] monthlySavings;
+ private double monthlyContribution;
+ public static final double ANNUAL_INTEREST_RATE = 0.05;
+
+ public EmployeeSavings(String firstName, String lastName) {
+ this(firstName, lastName, new Random().nextInt(800 - 100) + 100.0);
+ }
+
+ public EmployeeSavings(String firstName, String lastName, double monthlyContribution) {
+ super(firstName, "", lastName);
+ this.monthlyContribution = monthlyContribution;
+ this.accountValue = predictBalanceAfterMonths(12);
+ }
+
+ // what is d1, d2?
+ public EmployeeSavings(String firstName, String lastName, double[] d1, double[] d2) {
+ super(firstName, "", lastName);
+ }
+
+ public double getAccountValue() {
+ return this.accountValue;
+ }
+
+ public double[] getMonthlyInterests() {
+ return this.monthlyInterests;
+ }
+
+ public double[] getMonthlySavings() {
+ return this.monthlySavings;
+ }
+
+ public double[] calculateInterests() {
+ this.monthlyInterests = new double[12];
+ for (int i = 1; i <= 12; i++) this.monthlyInterests[i - 1] = predictInterestAfterMonths(i);
+ return this.monthlyInterests;
+ }
+
+ public double[] generateMonthlySavings() {
+ this.monthlySavings = new double[12];
+ for (int i = 1; i <= 12; i++) this.monthlySavings[i - 1] = predictBalanceAfterMonths(i);
+ return this.monthlySavings;
+ }
+
+ public double predictBalanceAfterMonths(int months) {
+ double monthlyRate = ANNUAL_INTEREST_RATE / 12.0;
+ double balance = 0;
+
+ for (int i = 0; i < months; i++)
+ balance = (balance + this.monthlyContribution) * (1 + monthlyRate);
+
+ return Math.round(balance * 1000) / 1000.0;
+ }
+
+ public double predictInterestAfterMonths(int months) {
+ return Math.round(
+ (predictBalanceAfterMonths(months) - (months * this.monthlyContribution)) * 1000)
+ / 1000.0;
+ }
+
+ public static String getReport(EmployeeSavings[] accounts) {
+ ArrayList<String> statement = new ArrayList<String>();
+
+ for (EmployeeSavings account : accounts) statement.add(account.toString());
+
+ return String.join(System.lineSeparator(), statement);
+ }
+
+ @Override
+ public String toString() {
+ Currency currency = Currency.getInstance(Locale.getDefault());
+ return String.format(
+ "%s %s%.2f", super.getFirstName(), currency.getSymbol(), this.getAccountValue());
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/HailstoneSequence.java b/src/main/java/ca/mokhan/assignment1/HailstoneSequence.java
new file mode 100644
index 0000000..b0e3c48
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/HailstoneSequence.java
@@ -0,0 +1,17 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+
+public class HailstoneSequence {
+ public static ArrayList<Integer> getHailstoneSequence(int n) {
+ return getHailstoneSequence(n, new ArrayList<Integer>());
+ }
+
+ public static ArrayList<Integer> getHailstoneSequence(int n, ArrayList<Integer> items) {
+ items.add(n);
+
+ if (n == 1) return items;
+ else if (n % 2 == 0) return getHailstoneSequence(n / 2, items);
+ else return getHailstoneSequence((n * 3) + 1, items);
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/Number.java b/src/main/java/ca/mokhan/assignment1/Number.java
new file mode 100644
index 0000000..d96274f
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/Number.java
@@ -0,0 +1,46 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+
+public class Number {
+ public static boolean isDivisibleBy5(int n) {
+ return isDivisibleBy(n, 5);
+ }
+
+ public static boolean isDivisibleBy7(int n) {
+ return isDivisibleBy(n, 7);
+ }
+
+ public static boolean isOdd(int n) {
+ return !isDivisibleBy(n, 2);
+ }
+
+ public static boolean isPrime(int n) {
+ if (n <= 1) return false;
+
+ for (int i = n - 1; i > 1; i--) if (isDivisibleBy(n, i)) return false;
+
+ return true;
+ }
+
+ public static boolean isDivisibleBy(int n, int denominator) {
+ return n % denominator == 0;
+ }
+
+ public static ArrayList<String> iterate() {
+ ArrayList<String> items = new ArrayList<String>();
+ ArrayList<String> row = new ArrayList<String>();
+ for (Integer i = 0; i < 113; i++) {
+ row.clear();
+ row.add(String.format("%d", i));
+
+ if (isOdd(i)) row.add(String.format("%d is odd", i));
+ if (isDivisibleBy5(i)) row.add("hi five");
+ if (isDivisibleBy7(i + (i + 1))) row.add("wow");
+ if (isPrime(i)) row.add("prime");
+
+ items.add(String.join(",", row));
+ }
+ return items;
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/TaxReturn.java b/src/main/java/ca/mokhan/assignment1/TaxReturn.java
new file mode 100644
index 0000000..91a226a
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/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());
+ }
+}
diff --git a/src/main/java/ca/mokhan/assignment1/Triangle.java b/src/main/java/ca/mokhan/assignment1/Triangle.java
new file mode 100644
index 0000000..cf45ec2
--- /dev/null
+++ b/src/main/java/ca/mokhan/assignment1/Triangle.java
@@ -0,0 +1,29 @@
+package ca.mokhan.assignment1;
+
+public class Triangle {
+ public static double NULL = 0.0;
+ private double a, b, c;
+
+ public Triangle(double a, double b, double c) {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ }
+
+ public double getA() {
+ return this.a;
+ }
+
+ public double getB() {
+ if (this.b == NULL) this.b = Math.sqrt(Math.pow(this.getC(), 2) - Math.pow(this.getA(), 2));
+ return this.b;
+ }
+
+ public double getC() {
+ return this.c;
+ }
+
+ public boolean isRightTriangle() {
+ return Math.pow(this.getA(), 2) + Math.pow(this.getB(), 2) == Math.pow(this.getC(), 2);
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/AddressBookTest.java b/src/test/java/ca/mokhan/assignment1/AddressBookTest.java
new file mode 100644
index 0000000..fc2361d
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/AddressBookTest.java
@@ -0,0 +1,92 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AddressBookTest extends TestCase {
+ private AddressBook subject;
+
+ public AddressBookTest(String testName) {
+ super(testName);
+ this.subject = new AddressBook();
+ }
+
+ public static Test suite() {
+ return new TestSuite(AddressBookTest.class);
+ }
+
+ public void testFirstName() {
+ subject.setFirstName("mo");
+ assertEquals(subject.getFirstName(), "mo");
+ }
+
+ public void testMiddleName() {
+ subject.setMiddleName("tsuyoshi");
+ assertEquals(subject.getMiddleName(), "tsuyoshi");
+ }
+
+ public void testLastName() {
+ subject.setLastName("garrett");
+ assertEquals(subject.getLastName(), "garrett");
+ }
+
+ public void testHomeAddress() {
+ subject.setHomeAddress("1 University Dr, Athabasca, AB T9S 3A3");
+ assertEquals(subject.getHomeAddress(), "1 University Dr, Athabasca, AB T9S 3A3");
+ }
+
+ public void testBusinessPhone() {
+ subject.setBusinessPhone("1-800-788-9041");
+ assertEquals(subject.getBusinessPhone(), "1-800-788-9041");
+ }
+
+ public void testHomePhone() {
+ subject.setHomePhone("1-800-788-9041");
+ assertEquals(subject.getHomePhone(), "1-800-788-9041");
+ }
+
+ public void testCellPhone() {
+ subject.setCellPhone("1-800-788-9041");
+ assertEquals(subject.getCellPhone(), "1-800-788-9041");
+ }
+
+ public void testSkypeId() {
+ subject.setSkypeId("1-800-788-9041");
+ assertEquals(subject.getSkypeId(), "1-800-788-9041");
+ }
+
+ public void testFacebookId() {
+ subject.setFacebookId("1-800-788-9041");
+ assertEquals(subject.getFacebookId(), "1-800-788-9041");
+ }
+
+ public void testPersonalWebsite() {
+ subject.setPersonalWebSite("https://www.mokhan.ca/");
+ assertEquals(subject.getPersonalWebSite(), "https://www.mokhan.ca/");
+ }
+
+ public void testCompareNames() {
+ assertTrue(
+ Integer.parseInt(AddressBook.compareNames("Tsuyoshi M. Garret", "Takashi Shirogane")) > 0);
+ assertTrue(
+ Integer.parseInt(AddressBook.compareNames("Takashi Shirogane", "Tsuyoshi M. Garret")) < 0);
+ assertTrue(
+ Integer.parseInt(AddressBook.compareNames("Tsuyoshi Garret", "Tsuyoshi Garret")) == 0);
+ }
+
+ public void testCompareTo() {
+ AddressBook hunk = new AddressBook();
+ hunk.setFirstName("Tsuyoshi");
+ hunk.setLastName("Garrett");
+
+ AddressBook shiro = new AddressBook();
+ shiro.setFirstName("Takashi");
+ shiro.setLastName("Shirogane");
+
+ assertTrue(hunk.compareTo(shiro) > 0);
+ assertTrue(shiro.compareTo(hunk) < 0);
+ assertTrue(hunk.compareTo(hunk) == 0);
+ assertTrue(shiro.compareTo(shiro) == 0);
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/AppTest.java b/src/test/java/ca/mokhan/assignment1/AppTest.java
new file mode 100644
index 0000000..f4c16b8
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/AppTest.java
@@ -0,0 +1,19 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AppTest extends TestCase {
+ public AppTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(AppTest.class);
+ }
+
+ public void testApp() {
+ assertTrue(true);
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java b/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java
new file mode 100644
index 0000000..4b04ae0
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java
@@ -0,0 +1,61 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class BanffMarathonRunnerTest extends TestCase {
+ private BanffMarathonRunner john = new BanffMarathonRunner("John", "Lenthen", 243, 1);
+ private BanffMarathonRunner kate = new BanffMarathonRunner("Kate", "Hen", 265, 8);
+ private BanffMarathonRunner[] runners = {
+ new BanffMarathonRunner("Elena", "Brandon", 341, 1),
+ new BanffMarathonRunner("Thomas", "Molson", 273, 2),
+ new BanffMarathonRunner("Hamilton", "Winn", 278, 5),
+ new BanffMarathonRunner("Suzie", "Sarandin", 329, 7),
+ new BanffMarathonRunner("Philip", "Winne", 445, 9),
+ new BanffMarathonRunner("Alex", "Trebok", 275, 3),
+ new BanffMarathonRunner("Emma", "Pivoto", 275, 4),
+ this.john,
+ new BanffMarathonRunner("James", "Lean", 334, 1),
+ new BanffMarathonRunner("Jane", "Ostin", 412, 1),
+ new BanffMarathonRunner("Emily", "Car", 393, 4),
+ new BanffMarathonRunner("Daniel", "Hamshire", 299, 4),
+ new BanffMarathonRunner("Neda", "Bazdar", 343, 3),
+ new BanffMarathonRunner("Aaron", "Smith", 317, 6),
+ this.kate
+ };
+
+ public BanffMarathonRunnerTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(BanffMarathonRunnerTest.class);
+ }
+
+ public void testGetFastestRunner() {
+ assertEquals(this.john, BanffMarathonRunner.getFastestRunner(this.runners));
+ }
+
+ public void testGetSecondFastestRunner() {
+ assertEquals(this.kate, BanffMarathonRunner.getSecondFastestRunner(this.runners));
+ }
+
+ public void testGetAverageTime() {
+ assertEquals(321, BanffMarathonRunner.getAverageTime(this.runners));
+ }
+
+ public void testGetAboveAverageRunners() {
+ String expected =
+ String.join(
+ System.lineSeparator(),
+ "Elena 1",
+ "Suzie 7",
+ "Philip 9",
+ "James 1",
+ "Jane 1",
+ "Emily 4",
+ "Neda 3");
+ assertEquals(expected, BanffMarathonRunner.getAboveAverageRunners(this.runners));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java b/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java
new file mode 100644
index 0000000..e19d447
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java
@@ -0,0 +1,26 @@
+package ca.mokhan.assignment1;
+
+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/test/java/ca/mokhan/assignment1/CandidateTest.java b/src/test/java/ca/mokhan/assignment1/CandidateTest.java
new file mode 100644
index 0000000..6d2ca5e
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/CandidateTest.java
@@ -0,0 +1,62 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CandidateTest extends TestCase {
+ private Candidate[] candidates = {
+ new Candidate("Elena", "Brandon", 82.30, "poor", true, 0.5),
+ new Candidate("Thomas", "Molson", 85.10, "poor", false, 1.0),
+ new Candidate("Hamilton", "Winn", 77.77, "average", false, 0.8),
+ new Candidate("Suzie", "Sarandin", 69.93, "average", false, 0.0),
+ new Candidate("Philip", "Winne", 93.03, "average", true, 1.0),
+ new Candidate("Alex", "Trebok", 88.61, "poor", true, 0.7),
+ new Candidate("Emma", "Pivoto", 55.99, "excellent", false, 0.8),
+ new Candidate("John", "Lenthen", 87.49, "excellent", true, 0.9),
+ new Candidate("James", "Lean", 88.00, "excellent", false, 0.5),
+ new Candidate("Jane", "Ostin", 91.20, "average", true, 0.6),
+ new Candidate("Emily", "Car", 66.79, "excellent", false, 0.3),
+ new Candidate("Daniel", "Hamshire", 76.65, "average", true, 0.2),
+ new Candidate("Neda", "Bazdar", 55.89, "excellent", true, 0.5),
+ new Candidate("Aaron", "Smith", 90.01, "excellent", false, 0.3),
+ new Candidate("Kate", "Hen", 87.9, "poor", false, 0.8)
+ };
+
+ public CandidateTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(CandidateTest.class);
+ }
+
+ public void testGetEligibleCandidates() {
+ ArrayList<Candidate> eligibleCandidates = Candidate.getEligibleCandidates(this.candidates);
+ for (String expected :
+ new String[] {
+ "Hamilton", "Philip", "Alex", "Emma", "John", "James", "Jane", "Neda", "Aaron"
+ }) {
+ assertNotNull(
+ eligibleCandidates.stream()
+ .filter(x -> expected.equals(x.getFirstName()))
+ .findAny()
+ .orElse(null));
+ }
+ }
+
+ public void testIsElligibleWithGreaterThanRequiredGrade() {
+ assertTrue(new Candidate("Tsuyoshi", "Garrett", 85.0, "excellent", false, 0.0).isEligible());
+ }
+
+ public void testIsElligibleWithLessThanRequiredGrade() {
+ assertFalse(new Candidate("Tsuyoshi", "Garrett", 84.9, "average", false, 0.0).isEligible());
+ assertTrue(new Candidate("Tsuyoshi", "Garrett", 84.9, "average", false, 0.5).isEligible());
+ }
+
+ public void testIsElligibleWithPoorCommunication() {
+ assertTrue(new Candidate("Tsuyoshi", "Garrett", 85.0, "poor", true, 0.0).isEligible());
+ assertFalse(new Candidate("Tsuyoshi", "Garrett", 85.0, "poor", false, 0.0).isEligible());
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java b/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java
new file mode 100644
index 0000000..6696ce1
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java
@@ -0,0 +1,22 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CartesianCoordinateSystemTest extends TestCase {
+ private CartesianCoordinateSystem subject;
+
+ public CartesianCoordinateSystemTest(String testName) {
+ super(testName);
+ this.subject = new CartesianCoordinateSystem();
+ }
+
+ public static Test suite() {
+ return new TestSuite(CartesianCoordinateSystemTest.class);
+ }
+
+ public void testDistanceBetweenPoints() {
+ assertEquals(7.28, subject.calculateDistance(-2, -3, -4, 4));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/CommunicationTest.java b/src/test/java/ca/mokhan/assignment1/CommunicationTest.java
new file mode 100644
index 0000000..675492f
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/CommunicationTest.java
@@ -0,0 +1,43 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CommunicationTest extends TestCase {
+ public CommunicationTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(CommunicationTest.class);
+ }
+
+ public void testCompareTo() {
+ assertEquals(-1, Communication.Poor.compareTo(Communication.Average));
+ assertEquals(-1, Communication.Poor.compareTo(Communication.Excellent));
+ assertEquals(0, Communication.Poor.compareTo(Communication.Poor));
+
+ assertEquals(-1, Communication.Average.compareTo(Communication.Excellent));
+ assertEquals(1, Communication.Average.compareTo(Communication.Poor));
+ assertEquals(0, Communication.Average.compareTo(Communication.Average));
+
+ assertEquals(1, Communication.Excellent.compareTo(Communication.Average));
+ assertEquals(1, Communication.Excellent.compareTo(Communication.Poor));
+ assertEquals(0, Communication.Excellent.compareTo(Communication.Excellent));
+ }
+
+ public void testIsAtLeast() {
+ assertFalse(Communication.Poor.isAtLeast(Communication.Average));
+ assertFalse(Communication.Poor.isAtLeast(Communication.Excellent));
+ assertTrue(Communication.Poor.isAtLeast(Communication.Poor));
+
+ assertFalse(Communication.Average.isAtLeast(Communication.Excellent));
+ assertTrue(Communication.Average.isAtLeast(Communication.Poor));
+ assertTrue(Communication.Average.isAtLeast(Communication.Average));
+
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Average));
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Poor));
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Excellent));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java b/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java
new file mode 100644
index 0000000..5e9374b
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java
@@ -0,0 +1,83 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class EmployeeSavingsTest extends TestCase {
+ private EmployeeSavings subject;
+
+ public EmployeeSavingsTest(String testName) {
+ super(testName);
+ double monthlyContribution = 100.00;
+ this.subject = new EmployeeSavings("Tsuyoshi", "Garrett", monthlyContribution);
+ }
+
+ public static Test suite() {
+ return new TestSuite(EmployeeSavingsTest.class);
+ }
+
+ public void testPredictSavingsAfter1Month() {
+ // Bankers rounding rules would round this amount down to $100.41
+ // the $0.007 would go to the bank.
+ assertEquals(100.417, subject.predictBalanceAfterMonths(1));
+ assertEquals(201.252, subject.predictBalanceAfterMonths(2));
+ assertEquals(302.507, subject.predictBalanceAfterMonths(3));
+ }
+
+ public void testPredictInterestAfter1Month() {
+ // Bankers rounding rules would round this amount down to $100.41
+ // the $0.007 would go to the bank.
+ assertEquals(0.417, subject.predictInterestAfterMonths(1));
+ assertEquals(1.252, subject.predictInterestAfterMonths(2));
+ assertEquals(2.507, subject.predictInterestAfterMonths(3));
+ }
+
+ public void testGetAccountValue() {
+ assertEquals(subject.predictBalanceAfterMonths(12), subject.getAccountValue());
+ }
+
+ public void testCalculateInterests() {
+ assertEquals(0.417, subject.calculateInterests()[0]);
+ assertEquals(1.252, subject.calculateInterests()[1]);
+ assertEquals(2.507, subject.calculateInterests()[2]);
+ assertEquals(4.184, subject.calculateInterests()[3]);
+ assertEquals(6.285, subject.calculateInterests()[4]);
+ assertEquals(8.811, subject.calculateInterests()[5]);
+ assertEquals(11.764, subject.calculateInterests()[6]);
+ assertEquals(15.147, subject.calculateInterests()[7]);
+ assertEquals(18.96, subject.calculateInterests()[8]);
+ assertEquals(23.206, subject.calculateInterests()[9]);
+ assertEquals(27.886, subject.calculateInterests()[10]);
+ assertEquals(33.002, subject.calculateInterests()[11]);
+ }
+
+ public void testGenerateMonthlySavings() {
+ assertEquals(100.417, subject.generateMonthlySavings()[0]);
+ assertEquals(201.252, subject.generateMonthlySavings()[1]);
+ assertEquals(302.507, subject.generateMonthlySavings()[2]);
+ }
+
+ public void testGetReport() {
+ EmployeeSavings[] accounts =
+ new EmployeeSavings[] {
+ new EmployeeSavings("Elena", "Brandon"),
+ new EmployeeSavings("Thomas", "Molson"),
+ new EmployeeSavings("Hamilton", "Winn"),
+ new EmployeeSavings("Suzie", "Sarandin"),
+ new EmployeeSavings("Philip", "Winne"),
+ new EmployeeSavings("Alex", "Trebok"),
+ new EmployeeSavings("Emma", "Pivoto"),
+ new EmployeeSavings("John", "Lenthen"),
+ new EmployeeSavings("James", "Lean"),
+ new EmployeeSavings("Jane", "Ostin"),
+ new EmployeeSavings("Emily", "Car"),
+ new EmployeeSavings("Daniel", "Hamshire"),
+ new EmployeeSavings("Neda", "Bazdar"),
+ new EmployeeSavings("Aaron", "Smith"),
+ new EmployeeSavings("Kate", "Hen")
+ };
+ String report = EmployeeSavings.getReport(accounts);
+ for (EmployeeSavings account : accounts) assertTrue(report.contains(account.getFirstName()));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java b/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java
new file mode 100644
index 0000000..6dc1fea
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java
@@ -0,0 +1,39 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class HailstoneSequenceTest extends TestCase {
+ public HailstoneSequenceTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(HailstoneSequenceTest.class);
+ }
+
+ public void testGetHailstoneSequence() {
+ ArrayList<Integer> results = HailstoneSequence.getHailstoneSequence(15);
+
+ assertTrue(15 == results.get(0));
+ assertTrue(46 == results.get(1));
+ assertTrue(23 == results.get(2));
+ assertTrue(70 == results.get(3));
+ assertTrue(35 == results.get(4));
+ assertTrue(106 == results.get(5));
+ assertTrue(53 == results.get(6));
+ assertTrue(160 == results.get(7));
+ assertTrue(80 == results.get(8));
+ assertTrue(40 == results.get(9));
+ assertTrue(20 == results.get(10));
+ assertTrue(10 == results.get(11));
+ assertTrue(5 == results.get(12));
+ assertTrue(16 == results.get(13));
+ assertTrue(8 == results.get(14));
+ assertTrue(4 == results.get(15));
+ assertTrue(2 == results.get(16));
+ assertTrue(1 == results.get(17));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/NumberTest.java b/src/test/java/ca/mokhan/assignment1/NumberTest.java
new file mode 100644
index 0000000..1ef9d96
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/NumberTest.java
@@ -0,0 +1,58 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class NumberTest extends TestCase {
+ public NumberTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(NumberTest.class);
+ }
+
+ public void testIsDivisibleBy5() {
+ for (int i = 0; i < 113; i++)
+ if (i % 5 == 0) assertTrue(Number.isDivisibleBy5(i));
+ else assertFalse(Number.isDivisibleBy5(i));
+ }
+
+ public void testIsDivisibleBy7() {
+ for (int i = 0; i < 113; i++)
+ if (i % 7 == 0) assertTrue(Number.isDivisibleBy7(i));
+ else assertFalse(Number.isDivisibleBy7(i));
+ }
+
+ public void testIsOdd() {
+ for (int i = 0; i < 113; i++)
+ if (i % 2 == 0) assertFalse(Number.isOdd(i));
+ else assertTrue(Number.isOdd(i));
+ }
+
+ public void testIsPrime() {
+ List<Integer> primes =
+ Arrays.asList(
+ new Integer[] {
+ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
+ 83, 89, 97, 101, 103, 107, 109, 113
+ });
+
+ for (Integer i = 0; i < 113; i++)
+ if (primes.contains(i)) assertTrue(Number.isPrime(i));
+ else assertFalse(Number.isPrime(i));
+ }
+
+ public void testIterate() {
+ ArrayList<String> results = Number.iterate();
+ assertTrue(results.contains("0,hi five"));
+ assertTrue(results.contains("1,1 is odd"));
+ assertTrue(results.contains("2,prime"));
+ assertTrue(results.contains("3,3 is odd,wow,prime"));
+ assertTrue(results.contains("4"));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java b/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java
new file mode 100644
index 0000000..474f899
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java
@@ -0,0 +1,85 @@
+package ca.mokhan.assignment1;
+
+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());
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/TriangleTest.java b/src/test/java/ca/mokhan/assignment1/TriangleTest.java
new file mode 100644
index 0000000..7b85c01
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/TriangleTest.java
@@ -0,0 +1,25 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TriangleTest extends TestCase {
+ public TriangleTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TriangleTest.class);
+ }
+
+ public void testIsRightTriangle() {
+ assertFalse(new Triangle(45.0, 55.0, 75.0).isRightTriangle());
+ assertTrue(new Triangle(28.0, 45.0, 53.0).isRightTriangle());
+ }
+
+ public void testGetB() {
+ assertEquals(64.0, new Triangle(48.0, Triangle.NULL, 80.0).getB());
+ assertEquals(35.0, new Triangle(84.0, Triangle.NULL, 91.0).getB());
+ }
+}