Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Programming 02
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
gavin.white
Programming 02
Commits
37d91bb4
Commit
37d91bb4
authored
Dec 09, 2022
by
gavin.white
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
34611bdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
Complex.java
...s Exercises/Complex Numbers/javaassesex1/src/Complex.java
+59
-0
No files found.
Java Resit/assesment/Class Exercises/Complex Numbers/javaassesex1/src/Complex.java
0 → 100644
View file @
37d91bb4
public
class
Complex
{
public
double
real
;
public
double
imag
;
public
Complex
()
{
real
=
2.6
;
imag
=
5.2
;
}
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
()
{
return
Math
.
sqrt
(
real
*
real
+
imag
*
imag
);
}
public
double
argument
()
{
return
Math
.
atan2
(
imag
,
real
);
}
public
String
toString
()
{
// Handle the case where the real part is 0
if
(
real
==
0
&&
imag
!=
0
)
{
return
"j"
+
imag
;
}
// Handle the case where the imaginary part is 0
if
(
imag
==
0
&&
real
!=
0
)
{
return
real
+
""
;
}
// Handle the case where the imaginary part is negative
if
(
imag
<
0
)
{
return
real
+
" - j"
+
(-
imag
);
}
// Handle the case where both the real and imaginary parts are non-zero
return
real
+
" + j"
+
imag
;
}
public
Complex
add
(
Complex
other
)
{
double
real
=
this
.
real
+
other
.
real
;
double
imag
=
this
.
imag
+
other
.
imag
;
return
new
Complex
(
real
,
imag
);
}
}
\ 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