aboutsummaryrefslogtreecommitdiff
path: root/semestre 4/java/tme/tp2/Complexe.java
blob: afd6cee72c68d3d098acccaafc4bb48cb51f0e42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
    }
}