package ru.kpfu.itis.group11402.batyrova.Task057; import ru.kpfu.itis.group11402.batyrova.Task050.RationalFraction; /** * @author Elvira Batyrova * 402 * 057 */ public class RationalComplexNumber { private RationalFraction a; private RationalFraction b; public RationalFraction getA() { return a; } public void setA(RationalFraction a) { this.a = a; } public RationalFraction getB() { return b; } public void setB(RationalFraction b) { this.b = b; } public RationalComplexNumber() { this(new RationalFraction(), new RationalFraction()); } public RationalComplexNumber(RationalFraction a, RationalFraction b) { this.a = a; this.b = b; } public RationalComplexNumber add(RationalComplexNumber rcn) { return new RationalComplexNumber(this.a.add(rcn.getA()), this.b.add(rcn.getB())); } public RationalComplexNumber sub(RationalComplexNumber rcn) { return new RationalComplexNumber(this.a.sub(rcn.getA()), this.b.sub(rcn.getB())); } public RationalComplexNumber mult(RationalComplexNumber rcn) { return new RationalComplexNumber(this.a.mult(rcn.getA()).sub(this.b.mult(rcn.getB())), this.a.mult(rcn.getB()).add(this.b.mult(rcn.getA()))); } public String toString() { if (a.value() != 0) { if (b.value() > 0) { return (a.toString() + " + " + b.toString() + "i"); } else if (b.value() < 0) { return (a.toString() + " - " + b.abs().toString() + "i"); } else { return (a.toString() + ""); } } else if (b.value() != 0) { return (b.toString() + "i"); } else { return("0"); } } }