import java.text.DecimalFormat; /* An instance of this class represents a complex number. There are ** mutator methods --corresponding to the four core arithmetic operators-- ** by which an instance of the class can be modified. ** ** Authors: R. McCloskey and < STUDENT's NAME > ** Date: Feb. 2022 ** Collaborators: ... ** Known Defects: ... */ public class ComplexNumber { // instance variables // ------------------ private double realPart; // Stores the "real" part of this complex number private double imagPart; // Stores the "imaginary" part // constructors // ------------ /* Establishes this complex number as being a + bi. */ public ComplexNumber(double a, double b) { // STUB } /* Establishes this complex number as being 0 + 0i. */ public ComplexNumber() { this(0.0, 0.0); } /* Establishes this complex number as being identical to the given one. */ public ComplexNumber(ComplexNumber c) { this(c.realPart, c.imagPart); } // observers // --------- /* Returns the real part of this complex number. */ public double realPart() { return 0; } // STUB /* Returns the imaginary part of this complex number. */ public double imaginaryPart() { return 0; } // STUB /* Returns a string of the form "a + bi" describing this complex number, ** where each of 'a' and 'b' is a real number with up to four digits after ** the decimal point. */ public String toString() { final DecimalFormat df = new DecimalFormat("#.####"); return df.format(realPart) + " + " + df.format(imagPart) + "i"; } // mutators // -------- /* In effect, performs the assignment this = this + other, ** consistent with the rule that ** (a + bi) + (c + di) = (a+c) + (b+d)i. */ public void addTo(ComplexNumber other) { realPart = realPart + other.realPart; imagPart = imagPart + other.imagPart; } /* In effect, performs the assignment this = this - other, ** consistent with the rule that ** (a + bi) - (c + di) = (a-c) + (b-d)i. */ public void subtractFrom(ComplexNumber other) { // STUB } /* In effect, performs the assignment this = this * other, ** consistent with the rule that ** (a + bi) * (c + di) = (ac - bd) + (bc + ad)i. */ public void multiplyBy(ComplexNumber other) { // STUB } /* In effect, performs the assignment this = this / other, ** consistent with the rule that ** (a + bi) / (c + di) = ** ((ac + bd) / (c^2 + d^2)) + ((bc - ad) / (c^2 + d^2))i. */ public void divideBy(ComplexNumber other) { // STUB } }