Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
ComplexTest Prog 02 Lec 3 Ex 2 Formative
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jordan.dalby
ComplexTest Prog 02 Lec 3 Ex 2 Formative
Commits
9eef9328
Commit
9eef9328
authored
Feb 10, 2020
by
jordan.dalby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ ComplexTest commit
parent
07fc3d3f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
Complex.java
src/com/jordan/Complex.java
+22
-0
ComplexTest.java
src/com/jordan/ComplexTest.java
+2
-2
No files found.
src/com/jordan/Complex.java
View file @
9eef9328
...
...
@@ -48,4 +48,26 @@ public class Complex
return
c
;
}
@Override
public
String
toString
()
{
String
s
=
""
;
if
(
realPart
!=
0
)
s
+=
String
.
valueOf
(
this
.
realPart
);
if
(
realPart
!=
0
&&
imaginaryPart
!=
0
)
{
if
(
imaginaryPart
<
0
)
s
+=
" - "
;
else
s
+=
" + "
;
}
if
(
imaginaryPart
!=
0
)
{
s
+=
"j"
+
String
.
valueOf
(
Math
.
abs
(
this
.
imaginaryPart
));
}
return
s
;
}
}
src/com/jordan/ComplexTest.java
View file @
9eef9328
...
...
@@ -48,7 +48,7 @@ class ComplexTest {
void
testToString
()
{
/* toString() should return a string like 1.2 + j3.4 where 1.2 is the real part
* and 3.4 the imaginary part.
*
*
/
Complex
a
=
new
Complex
(
1.2
,
3.4
);
assertEquals
(
"1.2 + j3.4"
,
a
.
toString
());
Complex
b
=
new
Complex
(
1.2
,
0.0
);
...
...
@@ -56,6 +56,6 @@ class ComplexTest {
Complex
c
=
new
Complex
(
0.0
,
9.3
);
assertEquals
(
"j9.3"
,
c
.
toString
());
Complex
d
=
new
Complex
(
1.2
,
-
3.4
);
assertEquals("1.2 - j3.4", d.toString());
*/
assertEquals
(
"1.2 - j3.4"
,
d
.
toString
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment