Advertisement
Guest User

Untitled

a guest
May 20th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.58 KB | None | 0 0
  1.   class Complex(val real: Int ,val imaginary: Int) {
  2.     def +(operand: Complex) : Complex = {
  3.       new Complex( real + operand.real , imaginary + operand.imaginary)
  4.     }
  5.     def -(operand: Complex) : Complex = {
  6.       new Complex( real - operand.real , imaginary - operand.imaginary)
  7.     }
  8.     def *(operand: Complex) : Complex = {
  9.       new Complex(real * operand.real - imaginary * operand.imaginary, real * operand.imaginary + imaginary * operand.real)
  10.     }
  11.     override def toString(): String = {
  12.       real + (if (imaginary < 0) "" else  "+") + imaginary + "i"
  13.     }
  14.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement