aboutsummaryrefslogtreecommitdiff
path: root/semestre 4/java/tme/tp2/Complexe.java
diff options
context:
space:
mode:
Diffstat (limited to 'semestre 4/java/tme/tp2/Complexe.java')
-rw-r--r--semestre 4/java/tme/tp2/Complexe.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/semestre 4/java/tme/tp2/Complexe.java b/semestre 4/java/tme/tp2/Complexe.java
new file mode 100644
index 0000000..afd6cee
--- /dev/null
+++ b/semestre 4/java/tme/tp2/Complexe.java
@@ -0,0 +1,29 @@
+public final class Complexe {
+ public final double reelle;
+ public final double imag;
+
+ public Complexe(double reelle, double imag) {
+ this.reelle = reelle;
+ this.imag = imag;
+ }
+
+ public Complexe() {
+ this(Math.random() * 4 - 2, Math.random() * 4 - 2);
+ }
+
+ public String toString() {
+ return String.format("%f + %fi", reelle, imag);
+ }
+
+ public boolean estReel() {
+ return imag == 0;
+ }
+
+ public Complexe addition(Complexe c) {
+ return new Complexe(reelle + c.reelle, imag + c.imag);
+ }
+
+ public Complexe multiplication(Complexe c) {
+ return new Complexe(reelle * c.reelle - imag * c.imag, reelle * c.reelle + imag * c.imag);
+ }
+}