Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Assessment
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
reece.french
Java Assessment
Commits
c3554fe3
Commit
c3554fe3
authored
May 13, 2022
by
reece.french
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assessment Exercise 1
parent
2393fc38
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
0 deletions
+94
-0
Complex.java
Complex.java
+94
-0
No files found.
Complex.java
0 → 100644
View file @
c3554fe3
import
org.junit.internal.RealSystem
;
public
class
Complex
{
public
double
real
;
public
double
imag
;
public
Complex
()
{
real
=
0
;
imag
=
0
;
}
public
Complex
(
double
r
,
double
i
)
{
real
=
r
;
imag
=
i
;
double
d
=
Math
.
atan2
(
i
,
r
);
}
public
double
imag
()
{
return
imag
;
}
public
double
real
()
{
return
real
;
}
public
double
magnitude
()
{
double
realSquared
=
real
()
*
real
();
double
imagSquared
=
imag
()
*
imag
();
return
(
Math
.
sqrt
(
realSquared
+
imagSquared
));
}
public
double
argument
()
{
return
(
Math
.
atan2
(
imag
(),
real
()));
}
public
String
toString
()
{
String
out
=
""
;
if
(
real
()
>
0
)
{
out
+=
Double
.
toString
(
real
());
if
(
imag
()
>
0
){
out
+=
" + "
;
}
else
if
(
imag
()
<
0
){
out
+=
" - "
;
}
}
if
(
imag
()
>
0
){
out
+=
"j"
;
out
+=
Double
.
toString
(
imag
());
}
else
if
(
real
()
==
0
&&
imag
()
<
0
)
{
out
+=
"-"
;
out
+=
"j"
;
out
+=
Double
.
toString
(
imag
());
}
else
if
(
imag
()
<
0
){
out
+=
"j"
;
double
make_positive
=
-
imag
();
out
+=
Double
.
toString
(
make_positive
);
}
return
out
;
}
public
Complex
add
(
Complex
complexNum
)
{
Complex
a
=
new
Complex
(
real
,
imag
);
double
firstReal
=
a
.
real
;
double
firstImag
=
a
.
imag
;
Complex
b
=
complexNum
;
double
secondReal
=
b
.
real
;
double
secondImag
=
b
.
imag
;
double
c
=
firstReal
+
secondReal
;
double
d
=
firstImag
+
secondImag
;
Complex
answer
=
new
Complex
(
c
,
d
);
return
answer
;
}
public
static
void
main
(
String
[]
args
)
{
}
}
\ No newline at end of file
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