From 46e409f3ca33ec3c7546d0589301c2a4f967c10a Mon Sep 17 00:00:00 2001 From: mokha Date: Sun, 5 May 2019 19:25:48 -0600 Subject: collapse assignment1 dir --- .gitignore | 3 + README.md | 244 +++++++++++++++++++++ assignment1/.gitignore | 3 - assignment1/README.md | 244 --------------------- assignment1/pom.xml | 37 ---- .../java/ca/mokhan/assignment1/AddressBook.java | 178 --------------- .../src/main/java/ca/mokhan/assignment1/App.java | 7 - .../ca/mokhan/assignment1/BanffMarathonRunner.java | 51 ----- .../java/ca/mokhan/assignment1/BonusOnSavings.java | 36 --- .../main/java/ca/mokhan/assignment1/Candidate.java | 75 ------- .../assignment1/CartesianCoordinateSystem.java | 7 - .../java/ca/mokhan/assignment1/Communication.java | 40 ---- .../ca/mokhan/assignment1/EmployeeSavings.java | 84 ------- .../ca/mokhan/assignment1/HailstoneSequence.java | 17 -- .../main/java/ca/mokhan/assignment1/Number.java | 46 ---- .../main/java/ca/mokhan/assignment1/TaxReturn.java | 91 -------- .../main/java/ca/mokhan/assignment1/Triangle.java | 29 --- .../ca/mokhan/assignment1/AddressBookTest.java | 92 -------- .../test/java/ca/mokhan/assignment1/AppTest.java | 19 -- .../assignment1/BanffMarathonRunnerTest.java | 61 ------ .../ca/mokhan/assignment1/BonusOnSavingsTest.java | 26 --- .../java/ca/mokhan/assignment1/CandidateTest.java | 62 ------ .../assignment1/CartesianCoordinateSystemTest.java | 22 -- .../ca/mokhan/assignment1/CommunicationTest.java | 43 ---- .../ca/mokhan/assignment1/EmployeeSavingsTest.java | 83 ------- .../mokhan/assignment1/HailstoneSequenceTest.java | 39 ---- .../java/ca/mokhan/assignment1/NumberTest.java | 58 ----- .../java/ca/mokhan/assignment1/TaxReturnTest.java | 85 ------- .../java/ca/mokhan/assignment1/TriangleTest.java | 25 --- pom.xml | 37 ++++ .../java/ca/mokhan/assignment1/AddressBook.java | 178 +++++++++++++++ src/main/java/ca/mokhan/assignment1/App.java | 7 + .../ca/mokhan/assignment1/BanffMarathonRunner.java | 51 +++++ .../java/ca/mokhan/assignment1/BonusOnSavings.java | 36 +++ src/main/java/ca/mokhan/assignment1/Candidate.java | 75 +++++++ .../assignment1/CartesianCoordinateSystem.java | 7 + .../java/ca/mokhan/assignment1/Communication.java | 40 ++++ .../ca/mokhan/assignment1/EmployeeSavings.java | 84 +++++++ .../ca/mokhan/assignment1/HailstoneSequence.java | 17 ++ src/main/java/ca/mokhan/assignment1/Number.java | 46 ++++ src/main/java/ca/mokhan/assignment1/TaxReturn.java | 91 ++++++++ src/main/java/ca/mokhan/assignment1/Triangle.java | 29 +++ .../ca/mokhan/assignment1/AddressBookTest.java | 92 ++++++++ src/test/java/ca/mokhan/assignment1/AppTest.java | 19 ++ .../assignment1/BanffMarathonRunnerTest.java | 61 ++++++ .../ca/mokhan/assignment1/BonusOnSavingsTest.java | 26 +++ .../java/ca/mokhan/assignment1/CandidateTest.java | 62 ++++++ .../assignment1/CartesianCoordinateSystemTest.java | 22 ++ .../ca/mokhan/assignment1/CommunicationTest.java | 43 ++++ .../ca/mokhan/assignment1/EmployeeSavingsTest.java | 83 +++++++ .../mokhan/assignment1/HailstoneSequenceTest.java | 39 ++++ .../java/ca/mokhan/assignment1/NumberTest.java | 58 +++++ .../java/ca/mokhan/assignment1/TaxReturnTest.java | 85 +++++++ .../java/ca/mokhan/assignment1/TriangleTest.java | 25 +++ 54 files changed, 1560 insertions(+), 1560 deletions(-) create mode 100644 .gitignore create mode 100644 README.md delete mode 100644 assignment1/.gitignore delete mode 100644 assignment1/README.md delete mode 100644 assignment1/pom.xml delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/App.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/BonusOnSavings.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/Candidate.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/Communication.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/HailstoneSequence.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/Number.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/TaxReturn.java delete mode 100644 assignment1/src/main/java/ca/mokhan/assignment1/Triangle.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/AddressBookTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/AppTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/CandidateTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/CommunicationTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/NumberTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java delete mode 100644 assignment1/src/test/java/ca/mokhan/assignment1/TriangleTest.java create mode 100644 pom.xml create mode 100644 src/main/java/ca/mokhan/assignment1/AddressBook.java create mode 100644 src/main/java/ca/mokhan/assignment1/App.java create mode 100644 src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java create mode 100644 src/main/java/ca/mokhan/assignment1/BonusOnSavings.java create mode 100644 src/main/java/ca/mokhan/assignment1/Candidate.java create mode 100644 src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java create mode 100644 src/main/java/ca/mokhan/assignment1/Communication.java create mode 100644 src/main/java/ca/mokhan/assignment1/EmployeeSavings.java create mode 100644 src/main/java/ca/mokhan/assignment1/HailstoneSequence.java create mode 100644 src/main/java/ca/mokhan/assignment1/Number.java create mode 100644 src/main/java/ca/mokhan/assignment1/TaxReturn.java create mode 100644 src/main/java/ca/mokhan/assignment1/Triangle.java create mode 100644 src/test/java/ca/mokhan/assignment1/AddressBookTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/AppTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/CandidateTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/CommunicationTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/NumberTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/TaxReturnTest.java create mode 100644 src/test/java/ca/mokhan/assignment1/TriangleTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..612c5bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target +.idea +*.iml diff --git a/README.md b/README.md new file mode 100644 index 0000000..c090240 --- /dev/null +++ b/README.md @@ -0,0 +1,244 @@ +Assignment 1 + +1. Create a class named AddressBook that has the following field names: + +* firstName +* middleName +* lastName +* homeAddress +* businessPhone +* homePhone +* cellphone +* skypeId +* facebookId +* personalWebSite + +Use appropriate data types to store the values for these fields in AddressBook objects. +Create appropriate get and set methods to retrieve and assign values to these names. +For example `getMiddleName(viveAddressBook)` should return the middle name of the person `Vive`. +Similarly, `vive.setPersonalWebsite(url)` should set the personal website of the person `Vive` to the specified URL object. +Using the get and set methods, create a comparison method `compareNames(name1, name2)` that compares the first, middle, and last names of strings name1 and name2. +Assume that name1 and name2 follow the following format: "FirstName M. LastName". + +Test your program for correct, partially correct (e.g., name string without the middleName), +and incorrect inputs (e.g., phone number containing special characters). + + +2. 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 + +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 + +II. Another employee has committed to save $3000 per month. +His quarterly savings are as follows: + +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 + + +Write a program to compute the total bonus amount earned by these two employees in the year. + +```ruby +class BonusOnSavings + def compute_bonus(commitment, q1, q2, q3, q4) + end +end +``` + +3. Write a program that prompts the user to enter two points `(x1, y1)` and `(x2, y2)`. +Calculate and display the distance between the two points using the formula below. +Round the answer up to 2 decimal points. +You can use `Math.pow(a,0.5)` to compute the square root of an expression. +`Math.pow()` returns a double. + +For example, the distance between the points (−2, −3) and (−4, 4) is approximately 7.28, as shown below. + +4. A group of AU friends decide to run the Banff, Alberta, Marathon. +Their names, times (marathon completion time in minutes), and number of years participated are given below: + +| id | Name | time (mins) | years | +| --- | --- | --- | --- | +| 1 | Elena Brandon | 341 | 1 | +| 2 | Thomas Molson | 273 | 2 | +| 3 | Hamilton Winn | 278 | 5 | +| 4 | Suzie Sarandin | 329 | 7 | +| 5 | Philip Winne | 445 | 9 | +| 6 | Alex Trebok | 275 | 3 | +| 7 | Emma Pivoto | 275 | 4 | +| 8 | John Lenthen | 243 | 1 | +| 9 | James Lean | 334 | 1 | +| 10 | Jane Ostin | 412 | 1 | +| 11 | Emily Car | 393 | 4 | +| 12 | Daniel Hamshire | 299 | 4 | +| 13 | Neda Bazdar | 343 | 3 | +| 14 | Aaron Smith | 317 | 6 | +| 15 | Kate Hen | 265 | 8| + +Extend the AddressBook class from Problem 1 to store the additional data. +Now, write a method to find the fastest runner. +Print the name, address, and his/her time (in minutes) on three separate lines. +Find the second fastest runner. +Print the name, address, his/her time (in minutes), and the difference in time with the fastest runner. +Compute the average time of completion taken by these runners. +Finally, print the name and number of years participated for each runner if the runner’s time of completion is equal to or better than the average time of completion. + +5. Solve the following problem using a program: +Suppose you save $100 each month into a savings account with an annual interest rate of 5%. +Thus, the monthly interest rate is 0.05/12 = 0.00417. +After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417 +After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252 +And after the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417) = 302.507 +... and so on. + +Write a program that randomly generates monthly savings amounts for the 15 runners in Problem 4. +Each monthly saving should be in the range of $100 to $800. +Extend the AddressBook class to store the monthly savings generated by the random number generator. +Then, display the final account value for each of the 15 runners. + + +6. "The Pythagorean Theorem relates the lengths of the three sides of any right triangle. +The legs of a right triangle (the two sides of the triangle that meet at the right angle) +are customarily labelled as having lengths "a" and "b", and the hypotenuse +(the long side of the triangle, opposite the right angle) is labelled as having length "c". +The lengths are related by the following equation: a^2 + b^2 = c^2." +– http://www.purplemath.com/modules/pythagthm.htm + +This equation allows you to find the length of a side of a right triangle when they’ve given you the lengths for the other two sides, +and, going in the other direction, allows you to determine if a triangle is a right triangle when they’ve given you the lengths for all three sides. +This equation can alternatively be written as c = sqrt of (a^2+b^2). +You can find the square root of a number by calling the standard function Math.sqrt. + +For example, the statement `double y = Math.sqrt(x)` sets `y` to the square root of `x`. + +I. Given the right triangles described below, write a program to compute the lengths of the remaining sides using a program. +a. a=48, c=80 b = 64 +b. a=84, c=91 b = 35 + +```text + a^2 + b^2 = c^2 + b^2 = c^2 - a^2 + b = sqrt(c^2 - a^2) +``` + +II. Determine if the following triangles are right-angled triangles: +a. a=45, b=55, c=75 +b. a=28, b=45, c=53 + +7. Douglas Hofstadter’s Pulitzer-prize-winning book Gödel, Escher, Bach contains many interesting mathematical puzzles. + +In Chapter XII, Hofstadter mentions a wonderful problem that is well within the scope of the control statements in Java. + +The problem can be expressed as follows: + +* Pick some positive integer and call it n. +* If n is even, divide it by two. +* If n is odd, multiply it by three and add one. +Continue this process until n is equal to 1. + +Hofstadter illustrates this process with the following example, +starting with the number n = 15: +15 is odd, so I make 3n+1: 46 +46 is even, so I take half: 23 +23 is odd, so I make 3n+1: 70 +70 is even, so I take half: 35 +35 is odd, so I make 3n+1: 106 +106 is even, so I take half: 53 +53 is odd, so I make 3n+1: 160 +160 is even, so I take half: 80 +80 is even, so I take half: 40 +40 is even, so I take half: 20 +20 is even, so I take half: 10 +10 is even, so I take half: 5 +5 is odd, so I make 3n+1: 16 +16 is even, so I take half: 8 +8 is even, so I take half: 4 +4 is even, so I take half: 2 +2 is even, so I take half: 1 + +As you can see from this example, the numbers go up and down, but eventually—at least for all numbers that have ever been tried—come down to end in 1. +In some respects, this process is reminiscent of the formation of hailstones, +which get carried upward by the winds over and over again before they finally descend to the ground. +Because of this analogy, this sequence of numbers is usually called the Hailstone sequence, +although it goes by many other names as well. + +Write a program that reads in a number from the user and then displays the Hailstone sequence for that number, +followed by a line showing the number of steps taken to reach 1. + +8. Google Inc. is looking to recruit three of the Boston runners. + +The criteria for selection are as follows: + +* I. Average final marks in bachelor’s degree (store up to 2 decimal places). + The fifteen candidates have the following grades: 82.30%, 85.10%, 77.77%, 69.93%, 93.03%, 88.61%, 55.99%, 87.49%, 88.00%, 91.20%, 66.79%, 76.65%, 55.89%, 90.01%, and 87.9%. +* II. Ability to communicate as one of the three values – "excellent", "average", and "poor". + The fifteen candidates have the following ability to communicate, respectively: poor, poor, average, average, average, poor, excellent, excellent, excellent, average, excellent, average, excellent, excellent, poor. +* III. Innovation as one of the two values – "brilliant" and "average" (store as a Boolean; brilliant = true and average = false). + The fifteen candidates have the following innovative abilities: brilliant, average, average, average, brilliant, brilliant, average, brilliant, average, brilliant, average, brilliant, brilliant, average, average. +* IV. Ability to regulate one’s own skill as a probability value between 0 and 1.0 – 1.0 implies excellent regulatory capabilities and 0.0 implies no skills to regulate (store as a double). + The fifteen candidates have the following regulatory abilities: 0.5, 1.0, 0.8, 0.0, 1.0, 0.7, 0.8, 0.9, 0.5, 0.6, 0.3, 0.2, 0.5, 0.3, 0.8. + +Store these values for the fifteen candidates in an extended AddressBook class. + +In general, Google will not consider a candidate with average marks of less than 85%. + +Google will consider a candidate with average marks of less than 85% only if the candidate at least has 0.5 regulatory abilities and at least 'average' ability to communicate. + +Google will only consider a candidate with poor communication ability if the candidate has a 'brilliant' innovation capability. + +Write a program that will help Google to programmatically determine eligibility of the fifteen candidates for these positions, and print the output on the console. + +9. Write a program that iterates through numbers from 0 to 113 using a loop. +Print the numbers, one number per line. +As you print each number, say x, also print the following when appropriate, separated by commas: + +If the number is odd, print “x is odd” +If the number is divisible by 5, print “hi five” +If the total of a number (x) and its subsequent number (x+1) is a value divisible by 7, print “wow” +If the number is prime, print “prime”. + +10. Modify the following program to the specifications given below: + +* Add a new status – + SingleParent – where the tax is computed as a SINGLE but with a further reduction of $5000 per child. +* 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. + +Unknown status – if the status doesn’t belong to SINGLE or MARRIED or SINGLE_PARENT, then compute a 33% tax on the income. diff --git a/assignment1/.gitignore b/assignment1/.gitignore deleted file mode 100644 index 612c5bc..0000000 --- a/assignment1/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -target -.idea -*.iml diff --git a/assignment1/README.md b/assignment1/README.md deleted file mode 100644 index c090240..0000000 --- a/assignment1/README.md +++ /dev/null @@ -1,244 +0,0 @@ -Assignment 1 - -1. Create a class named AddressBook that has the following field names: - -* firstName -* middleName -* lastName -* homeAddress -* businessPhone -* homePhone -* cellphone -* skypeId -* facebookId -* personalWebSite - -Use appropriate data types to store the values for these fields in AddressBook objects. -Create appropriate get and set methods to retrieve and assign values to these names. -For example `getMiddleName(viveAddressBook)` should return the middle name of the person `Vive`. -Similarly, `vive.setPersonalWebsite(url)` should set the personal website of the person `Vive` to the specified URL object. -Using the get and set methods, create a comparison method `compareNames(name1, name2)` that compares the first, middle, and last names of strings name1 and name2. -Assume that name1 and name2 follow the following format: "FirstName M. LastName". - -Test your program for correct, partially correct (e.g., name string without the middleName), -and incorrect inputs (e.g., phone number containing special characters). - - -2. 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 - -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 - -II. Another employee has committed to save $3000 per month. -His quarterly savings are as follows: - -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 - - -Write a program to compute the total bonus amount earned by these two employees in the year. - -```ruby -class BonusOnSavings - def compute_bonus(commitment, q1, q2, q3, q4) - end -end -``` - -3. Write a program that prompts the user to enter two points `(x1, y1)` and `(x2, y2)`. -Calculate and display the distance between the two points using the formula below. -Round the answer up to 2 decimal points. -You can use `Math.pow(a,0.5)` to compute the square root of an expression. -`Math.pow()` returns a double. - -For example, the distance between the points (−2, −3) and (−4, 4) is approximately 7.28, as shown below. - -4. A group of AU friends decide to run the Banff, Alberta, Marathon. -Their names, times (marathon completion time in minutes), and number of years participated are given below: - -| id | Name | time (mins) | years | -| --- | --- | --- | --- | -| 1 | Elena Brandon | 341 | 1 | -| 2 | Thomas Molson | 273 | 2 | -| 3 | Hamilton Winn | 278 | 5 | -| 4 | Suzie Sarandin | 329 | 7 | -| 5 | Philip Winne | 445 | 9 | -| 6 | Alex Trebok | 275 | 3 | -| 7 | Emma Pivoto | 275 | 4 | -| 8 | John Lenthen | 243 | 1 | -| 9 | James Lean | 334 | 1 | -| 10 | Jane Ostin | 412 | 1 | -| 11 | Emily Car | 393 | 4 | -| 12 | Daniel Hamshire | 299 | 4 | -| 13 | Neda Bazdar | 343 | 3 | -| 14 | Aaron Smith | 317 | 6 | -| 15 | Kate Hen | 265 | 8| - -Extend the AddressBook class from Problem 1 to store the additional data. -Now, write a method to find the fastest runner. -Print the name, address, and his/her time (in minutes) on three separate lines. -Find the second fastest runner. -Print the name, address, his/her time (in minutes), and the difference in time with the fastest runner. -Compute the average time of completion taken by these runners. -Finally, print the name and number of years participated for each runner if the runner’s time of completion is equal to or better than the average time of completion. - -5. Solve the following problem using a program: -Suppose you save $100 each month into a savings account with an annual interest rate of 5%. -Thus, the monthly interest rate is 0.05/12 = 0.00417. -After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417 -After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252 -And after the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417) = 302.507 -... and so on. - -Write a program that randomly generates monthly savings amounts for the 15 runners in Problem 4. -Each monthly saving should be in the range of $100 to $800. -Extend the AddressBook class to store the monthly savings generated by the random number generator. -Then, display the final account value for each of the 15 runners. - - -6. "The Pythagorean Theorem relates the lengths of the three sides of any right triangle. -The legs of a right triangle (the two sides of the triangle that meet at the right angle) -are customarily labelled as having lengths "a" and "b", and the hypotenuse -(the long side of the triangle, opposite the right angle) is labelled as having length "c". -The lengths are related by the following equation: a^2 + b^2 = c^2." -– http://www.purplemath.com/modules/pythagthm.htm - -This equation allows you to find the length of a side of a right triangle when they’ve given you the lengths for the other two sides, -and, going in the other direction, allows you to determine if a triangle is a right triangle when they’ve given you the lengths for all three sides. -This equation can alternatively be written as c = sqrt of (a^2+b^2). -You can find the square root of a number by calling the standard function Math.sqrt. - -For example, the statement `double y = Math.sqrt(x)` sets `y` to the square root of `x`. - -I. Given the right triangles described below, write a program to compute the lengths of the remaining sides using a program. -a. a=48, c=80 b = 64 -b. a=84, c=91 b = 35 - -```text - a^2 + b^2 = c^2 - b^2 = c^2 - a^2 - b = sqrt(c^2 - a^2) -``` - -II. Determine if the following triangles are right-angled triangles: -a. a=45, b=55, c=75 -b. a=28, b=45, c=53 - -7. Douglas Hofstadter’s Pulitzer-prize-winning book Gödel, Escher, Bach contains many interesting mathematical puzzles. - -In Chapter XII, Hofstadter mentions a wonderful problem that is well within the scope of the control statements in Java. - -The problem can be expressed as follows: - -* Pick some positive integer and call it n. -* If n is even, divide it by two. -* If n is odd, multiply it by three and add one. -Continue this process until n is equal to 1. - -Hofstadter illustrates this process with the following example, -starting with the number n = 15: -15 is odd, so I make 3n+1: 46 -46 is even, so I take half: 23 -23 is odd, so I make 3n+1: 70 -70 is even, so I take half: 35 -35 is odd, so I make 3n+1: 106 -106 is even, so I take half: 53 -53 is odd, so I make 3n+1: 160 -160 is even, so I take half: 80 -80 is even, so I take half: 40 -40 is even, so I take half: 20 -20 is even, so I take half: 10 -10 is even, so I take half: 5 -5 is odd, so I make 3n+1: 16 -16 is even, so I take half: 8 -8 is even, so I take half: 4 -4 is even, so I take half: 2 -2 is even, so I take half: 1 - -As you can see from this example, the numbers go up and down, but eventually—at least for all numbers that have ever been tried—come down to end in 1. -In some respects, this process is reminiscent of the formation of hailstones, -which get carried upward by the winds over and over again before they finally descend to the ground. -Because of this analogy, this sequence of numbers is usually called the Hailstone sequence, -although it goes by many other names as well. - -Write a program that reads in a number from the user and then displays the Hailstone sequence for that number, -followed by a line showing the number of steps taken to reach 1. - -8. Google Inc. is looking to recruit three of the Boston runners. - -The criteria for selection are as follows: - -* I. Average final marks in bachelor’s degree (store up to 2 decimal places). - The fifteen candidates have the following grades: 82.30%, 85.10%, 77.77%, 69.93%, 93.03%, 88.61%, 55.99%, 87.49%, 88.00%, 91.20%, 66.79%, 76.65%, 55.89%, 90.01%, and 87.9%. -* II. Ability to communicate as one of the three values – "excellent", "average", and "poor". - The fifteen candidates have the following ability to communicate, respectively: poor, poor, average, average, average, poor, excellent, excellent, excellent, average, excellent, average, excellent, excellent, poor. -* III. Innovation as one of the two values – "brilliant" and "average" (store as a Boolean; brilliant = true and average = false). - The fifteen candidates have the following innovative abilities: brilliant, average, average, average, brilliant, brilliant, average, brilliant, average, brilliant, average, brilliant, brilliant, average, average. -* IV. Ability to regulate one’s own skill as a probability value between 0 and 1.0 – 1.0 implies excellent regulatory capabilities and 0.0 implies no skills to regulate (store as a double). - The fifteen candidates have the following regulatory abilities: 0.5, 1.0, 0.8, 0.0, 1.0, 0.7, 0.8, 0.9, 0.5, 0.6, 0.3, 0.2, 0.5, 0.3, 0.8. - -Store these values for the fifteen candidates in an extended AddressBook class. - -In general, Google will not consider a candidate with average marks of less than 85%. - -Google will consider a candidate with average marks of less than 85% only if the candidate at least has 0.5 regulatory abilities and at least 'average' ability to communicate. - -Google will only consider a candidate with poor communication ability if the candidate has a 'brilliant' innovation capability. - -Write a program that will help Google to programmatically determine eligibility of the fifteen candidates for these positions, and print the output on the console. - -9. Write a program that iterates through numbers from 0 to 113 using a loop. -Print the numbers, one number per line. -As you print each number, say x, also print the following when appropriate, separated by commas: - -If the number is odd, print “x is odd” -If the number is divisible by 5, print “hi five” -If the total of a number (x) and its subsequent number (x+1) is a value divisible by 7, print “wow” -If the number is prime, print “prime”. - -10. Modify the following program to the specifications given below: - -* Add a new status – - SingleParent – where the tax is computed as a SINGLE but with a further reduction of $5000 per child. -* 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. - -Unknown status – if the status doesn’t belong to SINGLE or MARRIED or SINGLE_PARENT, then compute a 33% tax on the income. diff --git a/assignment1/pom.xml b/assignment1/pom.xml deleted file mode 100644 index fe8b644..0000000 --- a/assignment1/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - 4.0.0 - ca.mokhan.assignment1 - assignment1 - jar - 1.0-SNAPSHOT - assignment1 - http://maven.apache.org - - - junit - junit - 3.8.1 - test - - - - 1.8 - 1.8 - - - - - com.coveo - fmt-maven-plugin - 2.8 - - - - format - - - - - - - diff --git a/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java b/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java deleted file mode 100644 index 9fcfa82..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java +++ /dev/null @@ -1,178 +0,0 @@ -package ca.mokhan.assignment1; - -import java.util.Objects; - -public class AddressBook implements Comparable { - 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/assignment1/src/main/java/ca/mokhan/assignment1/App.java b/assignment1/src/main/java/ca/mokhan/assignment1/App.java deleted file mode 100644 index 6dc05d2..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/App.java +++ /dev/null @@ -1,7 +0,0 @@ -package ca.mokhan.assignment1; - -public class App { - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/assignment1/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java b/assignment1/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java deleted file mode 100644 index afc0472..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java +++ /dev/null @@ -1,51 +0,0 @@ -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 winners = new ArrayList(); - - for (BanffMarathonRunner runner : runners) - if (runner.time >= average) winners.add(runner.toString()); - - return String.join(System.lineSeparator(), winners); - } -} diff --git a/assignment1/src/main/java/ca/mokhan/assignment1/BonusOnSavings.java b/assignment1/src/main/java/ca/mokhan/assignment1/BonusOnSavings.java deleted file mode 100644 index 41090ec..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/BonusOnSavings.java +++ /dev/null @@ -1,36 +0,0 @@ -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/assignment1/src/main/java/ca/mokhan/assignment1/Candidate.java b/assignment1/src/main/java/ca/mokhan/assignment1/Candidate.java deleted file mode 100644 index 7df9535..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/Candidate.java +++ /dev/null @@ -1,75 +0,0 @@ -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 getEligibleCandidates(Candidate[] candidates) { - ArrayList eligible = new ArrayList(); - - for (Candidate candidate : candidates) { - if (candidate.isEligible()) eligible.add(candidate); - } - - return eligible; - } -} diff --git a/assignment1/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java b/assignment1/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java deleted file mode 100644 index d6681f9..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/CartesianCoordinateSystem.java +++ /dev/null @@ -1,7 +0,0 @@ -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/assignment1/src/main/java/ca/mokhan/assignment1/Communication.java b/assignment1/src/main/java/ca/mokhan/assignment1/Communication.java deleted file mode 100644 index 2e4c2a8..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/Communication.java +++ /dev/null @@ -1,40 +0,0 @@ -package ca.mokhan.assignment1; - -public class Communication implements Comparable { - 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/assignment1/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java b/assignment1/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java deleted file mode 100644 index 44eac10..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java +++ /dev/null @@ -1,84 +0,0 @@ -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 statement = new ArrayList(); - - 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/assignment1/src/main/java/ca/mokhan/assignment1/HailstoneSequence.java b/assignment1/src/main/java/ca/mokhan/assignment1/HailstoneSequence.java deleted file mode 100644 index b0e3c48..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/HailstoneSequence.java +++ /dev/null @@ -1,17 +0,0 @@ -package ca.mokhan.assignment1; - -import java.util.ArrayList; - -public class HailstoneSequence { - public static ArrayList getHailstoneSequence(int n) { - return getHailstoneSequence(n, new ArrayList()); - } - - public static ArrayList getHailstoneSequence(int n, ArrayList 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/assignment1/src/main/java/ca/mokhan/assignment1/Number.java b/assignment1/src/main/java/ca/mokhan/assignment1/Number.java deleted file mode 100644 index d96274f..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/Number.java +++ /dev/null @@ -1,46 +0,0 @@ -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 iterate() { - ArrayList items = new ArrayList(); - ArrayList row = new ArrayList(); - 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/assignment1/src/main/java/ca/mokhan/assignment1/TaxReturn.java b/assignment1/src/main/java/ca/mokhan/assignment1/TaxReturn.java deleted file mode 100644 index 91a226a..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/TaxReturn.java +++ /dev/null @@ -1,91 +0,0 @@ -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/assignment1/src/main/java/ca/mokhan/assignment1/Triangle.java b/assignment1/src/main/java/ca/mokhan/assignment1/Triangle.java deleted file mode 100644 index cf45ec2..0000000 --- a/assignment1/src/main/java/ca/mokhan/assignment1/Triangle.java +++ /dev/null @@ -1,29 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/AddressBookTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/AddressBookTest.java deleted file mode 100644 index fc2361d..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/AddressBookTest.java +++ /dev/null @@ -1,92 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/AppTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/AppTest.java deleted file mode 100644 index f4c16b8..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/AppTest.java +++ /dev/null @@ -1,19 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java deleted file mode 100644 index 4b04ae0..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java +++ /dev/null @@ -1,61 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java deleted file mode 100644 index e19d447..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java +++ /dev/null @@ -1,26 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/CandidateTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/CandidateTest.java deleted file mode 100644 index 6d2ca5e..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/CandidateTest.java +++ /dev/null @@ -1,62 +0,0 @@ -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 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/assignment1/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java deleted file mode 100644 index 6696ce1..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java +++ /dev/null @@ -1,22 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/CommunicationTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/CommunicationTest.java deleted file mode 100644 index 675492f..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/CommunicationTest.java +++ /dev/null @@ -1,43 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java deleted file mode 100644 index 5e9374b..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java +++ /dev/null @@ -1,83 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java deleted file mode 100644 index 6dc1fea..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java +++ /dev/null @@ -1,39 +0,0 @@ -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 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/assignment1/src/test/java/ca/mokhan/assignment1/NumberTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/NumberTest.java deleted file mode 100644 index 1ef9d96..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/NumberTest.java +++ /dev/null @@ -1,58 +0,0 @@ -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 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 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/assignment1/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java deleted file mode 100644 index 474f899..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java +++ /dev/null @@ -1,85 +0,0 @@ -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/assignment1/src/test/java/ca/mokhan/assignment1/TriangleTest.java b/assignment1/src/test/java/ca/mokhan/assignment1/TriangleTest.java deleted file mode 100644 index 7b85c01..0000000 --- a/assignment1/src/test/java/ca/mokhan/assignment1/TriangleTest.java +++ /dev/null @@ -1,25 +0,0 @@ -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()); - } -} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fe8b644 --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + ca.mokhan.assignment1 + assignment1 + jar + 1.0-SNAPSHOT + assignment1 + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + 1.8 + 1.8 + + + + + com.coveo + fmt-maven-plugin + 2.8 + + + + format + + + + + + + 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 { + 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 winners = new ArrayList(); + + 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 getEligibleCandidates(Candidate[] candidates) { + ArrayList eligible = new ArrayList(); + + 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 { + 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 statement = new ArrayList(); + + 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 getHailstoneSequence(int n) { + return getHailstoneSequence(n, new ArrayList()); + } + + public static ArrayList getHailstoneSequence(int n, ArrayList 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 iterate() { + ArrayList items = new ArrayList(); + ArrayList row = new ArrayList(); + 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 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 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 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 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()); + } +} -- cgit v1.2.3