1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
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:
|