diff options
| author | mo <mo.khan@gmail.com> | 2019-05-25 15:27:51 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-05-25 15:27:51 -0600 |
| commit | 856c35dbc7080922bfff7c10a7a844a9d0a1cd65 (patch) | |
| tree | 739b413bc2a29adc35229ef2fd9b30581601a206 /src/Q6 | |
| parent | 46f68298527e0c59b9f34003b687259477093fde (diff) | |
start assignment 2
Diffstat (limited to 'src/Q6')
| -rw-r--r-- | src/Q6/README.md | 124 | ||||
| -rw-r--r-- | src/Q6/Triangle.java | 66 | ||||
| -rw-r--r-- | src/Q6/TriangleTest.java | 26 |
3 files changed, 0 insertions, 216 deletions
diff --git a/src/Q6/README.md b/src/Q6/README.md deleted file mode 100644 index 594f920..0000000 --- a/src/Q6/README.md +++ /dev/null @@ -1,124 +0,0 @@ -Learning Profile for Assignment #1, And Question #6 - -Name: Mo Khan -Student ID: 3431709 - -1. Problem Statement: - -"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 - -2. Description of the Code: - -The `Triangle` class accepts the length of size `A`, `B`, and `C` in the -constructor. I used the constant `Triangle.NULL` to represent a null -value, to indicate which side needed to be calculated. - -I assumed only side `B` needed to be calculated based on the problem -description but could have also checked side `A` or `C`. - -3. Errors and Warnings: - -```bash -モ mvn test -[INFO] Scanning for projects... -[INFO] -[INFO] -------------------< ca.mokhan.comp268:assignment1 >-------------------- -[INFO] Building assignment1 1.0-SNAPSHOT -[INFO] --------------------------------[ jar ]--------------------------------- -[INFO] -[INFO] --- fmt-maven-plugin:2.8:format (default) @ assignment1 --- -[INFO] Processed 47 files (0 reformatted). -[INFO] -[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ assignment1 --- -[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! -[INFO] skip non existing resourceDirectory /Users/mokha/development/gh/comp-268/src/main/resources -[INFO] -[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ assignment1 --- -[INFO] Changes detected - recompiling the module! -[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! -[INFO] Compiling 24 source files to /Users/mokha/development/gh/comp-268/target/classes -[INFO] -[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ assignment1 --- -[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! -[INFO] skip non existing resourceDirectory /Users/mokha/development/gh/comp-268/src/test/resources -[INFO] -[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ assignment1 --- -[INFO] Changes detected - recompiling the module! -[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! -[INFO] Compiling 24 source files to /Users/mokha/development/gh/comp-268/target/test-classes -[INFO] -[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ assignment1 --- -[INFO] Surefire report directory: /Users/mokha/development/gh/comp-268/target/surefire-reports - -------------------------------------------------------- - T E S T S -------------------------------------------------------- -Running ca.mokhan.comp268.AppTest -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 sec -Running ca.mokhan.test.CandidateTest -Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.053 sec -Running ca.mokhan.test.NumberTest -Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.021 sec -Running ca.mokhan.test.EmployeeSavingsTest -Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec -Running ca.mokhan.test.CartesianCoordinateSystemTest -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec -Running ca.mokhan.test.CommunicationTest -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec -Running ca.mokhan.test.TaxReturnTest -Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec -Running ca.mokhan.test.BanffMarathonRunnerTest -Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec -Running ca.mokhan.test.AddressBookTest -Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec -Running ca.mokhan.test.TriangleTest -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec -Running ca.mokhan.test.BonusOnSavingsTest -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec -Running ca.mokhan.test.HailstoneSequenceTest -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - -Results : - -Tests run: 52, Failures: 0, Errors: 0, Skipped: 0 - -[INFO] ------------------------------------------------------------------------ -[INFO] BUILD SUCCESS -[INFO] ------------------------------------------------------------------------ -[INFO] Total time: 3.620 s -[INFO] Finished at: 2019-05-13T21:26:40-06:00 -[INFO] ------------------------------------------------------------------------ -``` - -4. Sample Input and Output: -[Provide some test cases with sample input and output of your program.] - -Tests are available in `TriangleTest.java`. - -5. Discussion: diff --git a/src/Q6/Triangle.java b/src/Q6/Triangle.java deleted file mode 100644 index 3e641ce..0000000 --- a/src/Q6/Triangle.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Assignment 1, COMP268 Class: Triangle.java - * - * @description Represents a Triangle - * @author: mo khan Student ID: 3431709 - * @date May 8, 2019 - * @version 1.0 - */ -package Q6; - -public class Triangle { - public static double NULL = 0.0; - private double a, b, c; - - /** - * Constructs a Triangle - * - * @param a the length of side A - * @param b the length of side B - * @param c the length of side C - */ - public Triangle(double a, double b, double c) { - this.a = a; - this.b = b; - this.c = c; - } - - /** @return the length of side A */ - public double getA() { - return this.a; - } - - /** @return the length of side B */ - public double getB() { - if (this.b == NULL) this.b = Math.sqrt(Math.pow(this.getC(), 2) - Math.pow(this.getA(), 2)); - return this.b; - } - - /** @return the length of side C */ - public double getC() { - return this.c; - } - - /** - * Determines if the triangle is a right angle triangle. - * - * @return boolean to indicate if the triangle is a right angle triangle - */ - public boolean isRightTriangle() { - return Math.pow(this.getA(), 2) + Math.pow(this.getB(), 2) == Math.pow(this.getC(), 2); - } - - /** @return a string with the length of each side */ - @Override - public String toString() { - return String.format("A: %f, B: %f, C: %f", this.getA(), this.getB(), this.getC()); - } - - public static void main(String[] args) { - System.out.println(new Triangle(48, Triangle.NULL, 80).toString()); - System.out.println(new Triangle(84, Triangle.NULL, 91).toString()); - - System.out.println(new Triangle(45, 55, 75).isRightTriangle()); - System.out.println(new Triangle(28, 45, 53).isRightTriangle()); - } -} diff --git a/src/Q6/TriangleTest.java b/src/Q6/TriangleTest.java deleted file mode 100644 index 8f4e035..0000000 --- a/src/Q6/TriangleTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package ca.mokhan.test; - -import Q6.*; -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()); - } -} |
