Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
assessmentExercises
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
cosmina.dunca
assessmentExercises
Commits
7da1e6b1
Commit
7da1e6b1
authored
Mar 16, 2022
by
cosmina.dunca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tasksDone
parent
bf380f35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
9 deletions
+30
-9
Complex.java
src/Complex.java
+30
-9
No files found.
src/Complex.java
View file @
7da1e6b1
...
@@ -12,40 +12,61 @@ public class Complex {
...
@@ -12,40 +12,61 @@ public class Complex {
public
Complex
(
double
r
,
double
i
)
public
Complex
(
double
r
,
double
i
)
{
{
real
=
r
;
this
.
real
=
r
;
imag
=
i
;
this
.
imag
=
i
;
double
d
=
Math
.
atan2
(
i
,
r
);
double
d
=
Math
.
atan2
(
i
,
r
);
}
}
public
double
imag
()
public
double
imag
1
()
{
{
return
imag
;
return
this
.
imag
;
}
}
public
double
real
()
public
double
real
1
()
{
{
return
real
;
return
this
.
real
;
}
}
public
double
magnitude
()
public
double
magnitude
()
{
{
return
1.0
;
return
Math
.
sqrt
(
Math
.
pow
(
this
.
real
,
2
)
+
Math
.
pow
(
imag
,
2
))
;
}
}
public
double
argument
()
public
double
argument
()
{
{
return
1.0
;
return
Math
.
atan2
(
this
.
imag
,
this
.
real
)
;
}
}
public
String
toString
()
public
String
toString
()
{
{
return
""
;
if
(
this
.
imag
<
0
)
{
if
(
this
.
real
!=
0
)
{
return
this
.
real
+
" - j"
+
this
.
imag
*
(-
1
);
}
else
{
return
"- j"
+
this
.
imag
*
(-
1
);
}
}
else
if
(
this
.
imag
>
0
)
{
if
(
this
.
real
!=
0
)
{
return
this
.
real
+
" + j"
+
this
.
imag
;
}
else
{
return
"j"
+
this
.
imag
;
}
}
else
{
return
this
.
real
+
""
;
}
}
}
public
Complex
add
(
Complex
complexNum
)
public
Complex
add
(
Complex
complexNum
)
{
{
Complex
answer
=
new
Complex
(
0.0
,
0.0
);
Complex
answer
=
new
Complex
(
0.0
,
0.0
);
answer
.
real
=
complexNum
.
real
+
this
.
real
;
answer
.
imag
=
complexNum
.
imag
+
this
.
imag
;
return
answer
;
return
answer
;
}
}
...
...
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