Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
formativeSubmission
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
quinn.haigh
formativeSubmission
Commits
3608fa81
Commit
3608fa81
authored
Feb 10, 2020
by
quinn.haigh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
second commit
parent
eeeee93c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
1 deletion
+102
-1
Complex.java
formativeSubmission/src/Complex.java
+101
-0
ComplexTest.java
formativeSubmission/src/ComplexTest.java
+1
-1
No files found.
formativeSubmission/src/Complex.java
0 → 100644
View file @
3608fa81
public
class
Complex
{
double
real
;
double
imag
;
public
Complex
()
{
real
=
0
;
imag
=
0
;
}
public
Complex
(
double
_real
,
double
_imag
)
{
real
=
_real
;
imag
=
_imag
;
}
public
double
real
()
{
return
real
;
}
public
double
imag
()
{
return
imag
;
}
public
double
magnitude
()
{
double
answerA
=
Math
.
pow
(
real
,
2
);
double
answerB
=
Math
.
pow
(
imag
,
2
);
double
result
=
answerA
+
answerB
;
double
mag
=
Math
.
sqrt
(
result
);
return
mag
;
}
public
double
argument
()
{
double
arg
=
Math
.
atan2
(
imag
,
real
);
return
arg
;
}
public
Complex
add
(
Complex
b
)
{
Complex
a
=
this
;
double
ansA
=
a
.
real
+
b
.
real
;
double
ansB
=
a
.
imag
+
b
.
imag
;
return
new
Complex
(
ansA
,
ansB
);
}
public
String
toString
()
{
if
(
real
==
0.0
)
{
String
stringI
=
Double
.
toString
(
imag
);
return
"j"
+
stringI
;
}
if
(
imag
==
0.0
)
{
String
stringR
=
Double
.
toString
(
real
);
return
stringR
;
}
if
(
imag
<
0.0
)
{
String
stringR
=
Double
.
toString
(
real
);
double
negate
=
Math
.
abs
(
imag
);
String
stringI
=
Double
.
toString
(
negate
);
return
stringR
+
" - "
+
"j"
+
stringI
;
}
else
{
String
stringR
=
Double
.
toString
(
real
);
String
stringI
=
Double
.
toString
(
imag
);
return
stringR
+
" + "
+
"j"
+
stringI
;
}
}
}
formativeSubmission/ComplexTest.java
→
formativeSubmission/
src/
ComplexTest.java
View file @
3608fa81
...
...
@@ -45,7 +45,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
);
...
...
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