package drills.drill01.exercise4 import drills.drill01.exercise2.PrintService import java.rmi.Remote import java.rmi.RemoteException import java.rmi.server.UnicastRemoteObject interface Math : Remote { @Throws(RemoteException::class) fun getFactOf(n: Int): Long @Throws(RemoteException::class) fun getFactOf(n: Int, ps: PrintService) } class MathImpl : Math, UnicastRemoteObject() { override fun getFactOf(n: Int): Long = fact(n) override fun getFactOf(n: Int, ps: PrintService) { ps.print("The factorial of $n is ${fact(n)}") } private fun fact(n: Int): Long { return if (n <= 1) 1 else n * fact(n - 1) } }