Catch- Tunisia
Take a moment to rationalize your perspectiveunknown
scala
2 years ago
1.0 kB
4
Indexable
object Catch22Algorithm { def main(args: Array[String]): Unit = { val maxTime = 11 // maximum time required to get residency val visaDuration = 3 // duration of visa val residencyFine = 300 // fine for getting/renewing residency val overstayFine = 40 // fine for each week of overstay def calculateFine(time: Int): Int = { var fine = 0 if (time > visaDuration) { val overstayTime = time - visaDuration fine += overstayTime * overstayFine } fine += residencyFine fine } def calculateOutcome(time: Int): String = { if (time <= visaDuration) { "Leave and pay 300 dinars for residency" } else if (time <= maxTime) { s"Stay and pay ${calculateFine(time)} dinars in fines" } else { "Stay and pay 20000 dinars in fines" } } println("Enter the time spent trying to get residency in months: ") val time = scala.io.StdIn.readInt() println(calculateOutcome(time)) } }
Editor is loading...