Search⌘ K
AI Features

Challenge: Operator Overloading

Explore how to implement operator overloading in Kotlin by multiplying complex numbers. Understand the mathematical logic behind complex multiplication and apply it by defining the * operator within a Complex class to return correct results.

Problem statement

In this challenge, we want to multiply two complex numbers by overloading the * operator.

Multiplication between complex numbers takes place as illustrated in the example below:

In general,

(a+bi)(c+di)=acbdreal+(ad+bc)iimaginary(a+bi)(c+di) = \underbrace{ac-bd}_{real}+\underbrace{(ad+bc)i}_{imaginary} ...