Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Exercise 1
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
henry.ewen
Exercise 1
Commits
c0c4f587
Commit
c0c4f587
authored
May 15, 2022
by
Henry Ewen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished
parent
792fd555
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
11 deletions
+25
-11
App.class
bin/App.class
+0
-0
AppTest.class
bin/AppTest.class
+0
-0
Complex.class
bin/Complex.class
+0
-0
AppTest.java
src/AppTest.java
+0
-3
Complex.java
src/Complex.java
+25
-8
No files found.
bin/App.class
View file @
c0c4f587
No preview for this file type
bin/AppTest.class
View file @
c0c4f587
No preview for this file type
bin/Complex.class
View file @
c0c4f587
No preview for this file type
src/AppTest.java
View file @
c0c4f587
...
@@ -30,7 +30,6 @@ public class AppTest {
...
@@ -30,7 +30,6 @@ public class AppTest {
assertEquals
(
0.87520335
,
a
.
argument
(),
1
e
-
6
);
assertEquals
(
0.87520335
,
a
.
argument
(),
1
e
-
6
);
}
}
@Test
@Test
public
void
testToString
()
{
public
void
testToString
()
{
/* toString() should return a string like 1.2 + j3.4 where 1.2 is the real part
/* toString() should return a string like 1.2 + j3.4 where 1.2 is the real part
...
@@ -55,6 +54,4 @@ public class AppTest {
...
@@ -55,6 +54,4 @@ public class AppTest {
assertEquals
(
19.7
,
c
.
real
(),
1
e
-
6
);
assertEquals
(
19.7
,
c
.
real
(),
1
e
-
6
);
assertEquals
(
26.4
,
c
.
imag
(),
1
e
-
6
);
assertEquals
(
26.4
,
c
.
imag
(),
1
e
-
6
);
}
}
}
}
src/Complex.java
View file @
c0c4f587
...
@@ -14,7 +14,6 @@ public class Complex {
...
@@ -14,7 +14,6 @@ public class Complex {
{
{
real
=
r
;
real
=
r
;
imag
=
i
;
imag
=
i
;
double
d
=
Math
.
atan2
(
i
,
r
);
}
}
public
double
imag
()
public
double
imag
()
...
@@ -29,25 +28,43 @@ public class Complex {
...
@@ -29,25 +28,43 @@ public class Complex {
public
double
magnitude
()
public
double
magnitude
()
{
{
return
1.0
;
return
Math
.
sqrt
(
Math
.
pow
(
real
,
2
)+(
Math
.
pow
(
imag
,
2
)))
;
}
}
public
double
argument
()
public
double
argument
()
{
{
return
1.0
;
return
Math
.
atan
(
imag
/
real
)
;
}
}
public
String
toString
()
public
String
toString
()
{
{
return
""
;
String
imagine_string
=
Double
.
toString
(
imag
);
String
real_string
=
Double
.
toString
(
real
);
if
(
real
!=
0
)
{
if
(
imag
!=
0
)
{
if
(
imag
<
0
)
{
String
imagine_string2
=
imagine_string
.
replace
(
"-"
,
""
);
return
real_string
+
" - "
+
"j"
+
imagine_string2
;
}
return
real_string
+
" + "
+
"j"
+
imagine_string
;
}
else
{
return
real_string
;
}
}
else
{
return
"j"
+
imagine_string
;
}
}
}
public
Complex
add
(
Complex
complexNum
)
public
Complex
add
(
Complex
complexNum
)
{
{
Complex
answer
=
new
Complex
(
0.0
,
0.0
);
Complex
ans
=
new
Complex
(
0.0
,
0.0
);
ans
.
real
=
complexNum
.
real
+
real
;
return
answer
;
ans
.
imag
=
complexNum
.
imag
+
imag
;
return
ans
;
}
}
}
}
\ 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